{"__v":77,"_id":"551ef4f04986f62b00a72055","category":{"__v":2,"_id":"551ef4ef4986f62b00a72036","pages":["551ef4f04986f62b00a72052","551ef4f04986f62b00a72053","551ef4f04986f62b00a72054","551ef4f04986f62b00a72055","55e762f559f5ed21004f554c"],"project":"542b6018044e1e2200413772","version":"551ef4ef4986f62b00a7202e","reference":false,"createdAt":"2014-10-20T19:30:55.496Z","from_sync":false,"order":1,"slug":"ios","title":"iOS"},"parentDoc":null,"project":"542b6018044e1e2200413772","user":"54455e750a8dbc1a00ff699c","version":{"__v":7,"_id":"551ef4ef4986f62b00a7202e","forked_from":"542b6018044e1e2200413775","project":"542b6018044e1e2200413772","createdAt":"2015-04-03T20:15:43.149Z","releaseDate":"2015-04-03T20:15:43.149Z","categories":["551ef4ef4986f62b00a7202f","551ef4ef4986f62b00a72030","551ef4ef4986f62b00a72031","551ef4ef4986f62b00a72032","551ef4ef4986f62b00a72033","551ef4ef4986f62b00a72034","551ef4ef4986f62b00a72035","551ef4ef4986f62b00a72036","551ef4ef4986f62b00a72037","551ef4ef4986f62b00a72038","551ef4ef4986f62b00a72039","551ef4ef4986f62b00a7203a","551ef4ef4986f62b00a7203b","551ef4ef4986f62b00a7203c","551ef4ef4986f62b00a7203d","551ef4ef4986f62b00a7203e","55d7f1879510f00d007ec727","56b94a5a9fc0de1700b60ae9","56bd0e48ac1c5c1900b2dbe4","56d74afc3eb4dd0b0020196a","5723ab8a1f41110e003081ed","576b4dd327d6252b00085422"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"updates":[],"createdAt":"2014-10-21T19:46:34.301Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":3,"body":"[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"List of Methods\"\n}\n[/block]\n[initWithLaunchOptions](#initWithLaunchOptions)\n\n[registerForPushNotifications](#registerForPushNotifications)\n\n[sendTag](#sendTag)\n\n[sendTags](#sendTags)\n\n[getTags](#getTags)\n\n[deleteTag](#deleteTag)\n\n[deleteTags](#deleteTags)\n\n[IdsAvailable](#IdsAvailable)\n\n[enableInAppAlertNotification](#enableInAppAlertNotification)\n\n[setSubscription](#setSubscription)\n\n[postNotification](#postNotification)\n\n[promptLocation](#promptLocation)\n\n[setLogLevel](#setLogLevel)\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"List of Block Callbacks\"\n}\n[/block]\n[OneSignalHandleNotificationBlock](#OneSignalHandleNotificationBlock)\n\n[OneSignalResultSuccessBlock](#OneSignalResultSuccessBlock)\n\n[OneSignalFailureBlock](#OneSignalFailureBlock)\n\n[OneSignalIdsAvailableBlock](#OneSignalIdsAvailableBlock) \n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Methods\"\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"initWithLaunchOptions\\\">\"\n}\n[/block]\n#### initWithLaunchOptions\nMust be called from `didFinishLaunchingWithOptions` in `AppDelegate.m`. Instead of passing in appId here you can also add OneSignal_APPID as a key in your plist file and place your OneSignal app Id as a value there.\n\n __Parameters__\n - __`NSDictionary*` _launchOptions___ - launchOptions that you received from didFinishLaunchingWithOptions\n - __`NSString*` _appId___ - Your OneSignal app id found on the settings page at onesignal.com.\n - __[`OneSignalHandleNotificationBlock`](#OneSignalHandleNotificationBlock) _callback(Optional)___ - Function to be called when a notification is opened or received while the app is in use.\n - __`BOOL` _autoRegister(Optional)___ - Default true. Automatically show the iOS system prompt to accept push notifications. You can pass in false to delay this pop-up and then call `registerForPushNotifications` to prompt them later.\n*NOTE: `application:didRegisterForRemoteNotificationsWithDeviceToken:` will still fire even if `false` is passed to `autoRegister`, however the user will not be prompted for Notifications. This behavior will happen on iOS 8+ devices.*\n\n__Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {\\n self.oneSignal = [[OneSignal alloc]\\n initWithLaunchOptions:launchOptions\\n appId::::at:::\\\"b2f7f966-d8cc-11e4-bed1-df8f05be55ba\\\"\\n handleNotification:^(NSString* message, NSDictionary* additionalData, BOOL isActive) {\\n NSLog(@\\\"OneSignal Notification opened:\\\\nMessage: %@\\\", message);\\n \\n if (additionalData) {\\n NSLog(@\\\"additionalData: %@\\\", additionalData);\\n \\n // Check for and read any custom values you added to the notification\\n // This done with the \\\"Additional Data\\\" section the dashboard.\\n // OR setting the 'data' field on our REST API.\\n NSString* customKey = additionalData[@\\\"customKey\\\"];\\n if (customKey)\\n NSLog(@\\\"customKey: %@\\\", customKey);\\n }\\n }];\\n}\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\\n let oneSignal = OneSignal(launchOptions: launchOptions, appId: \\\"b2f7f966-d8cc-11e4-bed1-df8f05be55ba\\\", handleNotification: { (message, additionalData, isActive) in\\n NSLog(\\\"OneSignal Notification opened:\\\\nMessage: %@\\\", message)\\n \\n if additionalData != nil {\\n NSLog(\\\"additionalData: %@\\\", additionalData)\\n // Check for and read any custom values you added to the notification\\n // This done with the \\\"Additonal Data\\\" section the dashbaord.\\n // OR setting the 'data' field on our REST API.\\n if let customKey = additionalData[\\\"customKey\\\"] as! String? {\\n NSLog(\\\"customKey: %@\\\", customKey)\\n }\\n }\\n }, autoRegister: false)\\n}\",\n \"language\": \"swift\",\n \"name\": null\n }\n ]\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"registerForPushNotifications\\\">\"\n}\n[/block]\n#### registerForPushNotifications\nCall when you want to prompt the user to accept push notifications. Only call once and only if you passed false to `initWithLaunchOptions autoRegister:`.\n\n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal registerForPushNotifications];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.registerForPushNotifications()\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"sendTag\\\">\"\n}\n[/block]\n#### sendTag\nTag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com) to target these users. Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.\n\n- __Parameters__\n - __`NSString*` _key___ - Key of your choosing to create or update.\n - __`NSString*` _value___ - Value to set on the key.\n - _NOTE:_ Passing in a blank String deletes the key, you can also call deleteTag or deleteTags.\n - __`OneSignalResultSuccessBlock` _onSuccess(Optional)___ - Call if there were no errors sending the tag.\n - __`OneSignalFailureBlock` _onFailure(Optional)___ - Called if there was an error.\n\n\n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal sendTag:@\\\"key\\\" value:@\\\"value\\\"];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.sendTag(\\\"key\\\", value: \\\"value\\\")\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"sendTags\\\">\"\n}\n[/block]\n#### sendTags\nTag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com) to target these users.\n\n- __Parameters__\n - __`NSDictionary*` _keyValues___ - Key value pairs of your choosing to create or update.\n - _NOTE:_ Passing in a blank `NSString*` as a value deletes the key, you can also call `deleteTag` or `deleteTags`.\n - __`OneSignalResultSuccessBlock` _onSuccess(Optional)___ - Call if there were no errors sending the tag.\n - __`OneSignalFailureBlock` _onFailure(Optional)___ - Called if there was an error.\n\n \n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal sendTags:@{@\\\"key1\\\" : @\\\"value1\\\", @\\\"key2\\\" : @\\\"value2\\\"}];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.sendTags([\\\"key1\\\": \\\"value1\\\", \\\"key2\\\": \\\"value2\\\"])\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"getTags\\\">\"\n}\n[/block]\n#### getTags\nRetrieve a list of tags that have been set on the user from the OneSignal server.\n\n- __Parameters__\n - __`OneSignalResultSuccessBlock` _successBlock___ - Called when tags are received from OneSignal's server.\n - __`OneSignalFailureBlock` _onFailure(Optional)___ - Called if there was an error.\n\n \n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal getTags:^(NSDictionary* tags) {\\n\\tNSLog(@\\\"%@\\\", tags);\\n}];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.getTags({ (tags) in\\n\\tNSLog(\\\"%@\\\", tags)\\n})\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"deleteTag\\\">\"\n}\n[/block]\n#### deleteTag\nDeletes a tag that was previously set on a user with `sendTag` or `sendTags`. Use `deleteTags` if you need to delete more than one.\n\n- __Parameters__\n - __`NSString*` _key___ - Key to remove.\n - __`OneSignalResultSuccessBlock` _onSuccess(Optional)___ - Call if there were no errors.\n - __`OneSignalFailureBlock` _onFailure(Optional)___ - Called if there was an error.\n \n \n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal deleteTag:@\\\"key\\\"];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.deleteTag(\\\"key\\\")\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"deleteTags\\\">\"\n}\n[/block]\n#### deleteTags\nDeletes tags that were previously set on a user with `sendTag` or `sendTags`.\n\n- __Parameters__\n - __`NSArray*` _keys___ - Keys to remove.\n - __`OneSignalResultSuccessBlock` _onSuccess(Optional)___ - Call if there were no errors.\n - __`OneSignalFailureBlock` _onFailure(Optional)___ - Called if there was an error.\n \n \n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal deleteTags:@[@\\\"key1\\\", @\\\"key2\\\"]];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.deleteTags([\\\"key1\\\", \\\"key2\\\"])\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"IdsAvailable\\\">\"\n}\n[/block]\n#### IdsAvailable\nLets you retrieve the OneSignal user id and push token. Your callback block is called after the device is successfully registered with OneSignal. pushToken will be nil if the user did not accept push notifications.\n\n- __Parameters__\n - __`OneSignalIdsAvailableBlock` _IdsAvailableBlock___ - Called when the user id is available.\n\n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal IdsAvailable:^(NSString* userId, NSString* pushToken) {\\n\\tNSLog(@\\\"UserId:%@\\\", userId);\\n\\tif (pushToken != nil)\\n\\t\\tNSLog(@\\\"pushToken:%@\\\", pushToken);\\n}];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.IdsAvailable({ (userId, pushToken) in\\n\\tNSLog(\\\"UserId:%@\\\", userId)\\n if (pushToken != nil) {\\n \\tNSLog(\\\"pushToken:%@\\\", pushToken)\\n }\\n})\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n\n<br>\n<div id=\"enableInAppAlertNotification\">\n#### enableInAppAlertNotification\nBy default this is false and notifications will not be shown when the user is in your app, instead the OneSignalHandleNotificationBlock is fired. If set to true notifications will be shown as native alert boxes if a notification is received when the user is in your app. The OneSignalHandleNotificationBlock is then fired after the alert box is closed.\n\n__Parameters__\n - __`BOOL` enable___\n\n__Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal enableInAppAlertNotification:true];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.enableInAppAlertNotification(true)\",\n \"language\": \"swift\"\n }\n ]\n}\n[/block]\n<br>\n<div id=\"setSubscription\">\n#### setSubscription\nYou can call this method with false to opt users out of receiving all notifications through OneSignal. You can pass true later to opt users back into notifications.\n\n__Parameters__\n - __`BOOL` enable___\n\n__Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal setSubscription:false];\",\n \"language\": \"objectivec\"\n }\n ]\n}\n[/block]\n<br>\n<div id=\"postNotification\">\n#### postNotification\nAllows you to send notifications from user to user or schedule ones in the future to be delivered to the current device.\n\n__Parameters__\n - __`NSDictionary*` _parameters___ - Dictionary of notification options, see our [create notification POST](http://documentation.onesignal.com/v2.0/docs/notifications-create-notification) call for all options.\n - __`OneSignalResultSuccessBlock` _onSuccess(Optional)___ - Called if there were no errors sending the notification.\n - __`OneSignalFailureBlock` _onFailure(Optional)___ - Called if there was an error.\n\n__Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[self.oneSignal postNotification:@{\\n @\\\"contents\\\" : @{@\\\"en\\\": @\\\"Test Message\\\"},\\n @\\\"include_player_ids\\\": @[@\\\"3009e210-3166-11e5-bc1b-db44eb02b120\\\"]\\n}];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.postNotification([\\\"contents\\\": [\\\"en\\\": \\\"Test Message\\\"], \\\"include_player_ids\\\": [\\\"3009e210-3166-11e5-bc1b-db44eb02b120\\\"]])\",\n \"language\": \"swift\"\n }\n ]\n}\n[/block]\nSee the [create notification](http://documentation.onesignal.com/v2.0/docs/notifications-create-notification) REST API POST call for a list of all possible options. Note: You can only use `include_player_ids` as a targeting parameter from your app. Other target options such as `tags` and `included_segments` require your OneSignal App REST API key which can only be used from your server.\n\n<br>\n<div id=\"promptLocation\">\n#### promptLocation\nPrompts the user for location permissions to allow geotagging from the OneSignal dashboard. This lets you send notifications based on the device's location.\n\n__Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[self.oneSignal promptLocation];\",\n \"language\": \"objectivec\"\n }\n ]\n}\n[/block]\nNote: Requires the follow entries in your .plist file.\n- `NSLocationUsageDescription`\n- `NSLocationWhenInUseUsageDescription`\n\n<br>\n<div id=\"setLogLevel\">\n#### setLogLevel\nEnable logging to help debug if you run into an issue setting up OneSignal. This selector is static so you can call it before OneSignal init. The following options are available with increasingly more information; ONE_S_LL_NONE, ONE_S_LL_FATAL, ONE_S_LL_ERROR, ONE_S_LL_WARN, ONE_S_LL_INFO, ONE_S_LL_DEBUG, ONE_S_LL_VERBOSE.\n\n__Parameters__\n - __`LOG_LEVEL` _logLevel___ - Sets the logging level to print to the Xcode log.\n - __`LOG_LEVEL` _visualLevel___ - Sets the logging level to show as alert dialogs.\n \n__Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[OneSignal setLogLevel:ONE_S_LL_DEBUG visualLevel:ONE_S_LL_DEBUG];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"OneSignal.setLogLevel(.LL_DEBUG, visualLevel: .LL_DEBUG)\",\n \"language\": \"swift\"\n }\n ]\n}\n[/block]\n<br>\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Block Callbacks\"\n}\n[/block]\n\n[block:html]\n{\n \"html\": \"<a name=\\\"OneSignalHandleNotificationBlock\\\">\"\n}\n[/block]\n\n#### OneSignalHandleNotificationBlock\nIs called when a OneSignal notification is tapped on or one is received while the app is in focus.\n\n - __Parameters__\n - __`NSString*` _message___ - Visible text the user sees on the push notification itself.\n - __`NSDictionary*` _additionalData___ - Key value pairs set on the additional data section on onesignal.com.\n - NOTE: If you set Action Buttons on your notification the actionSelected key will contain the id of the button pressed; \"\\__DEFAULT\\__\" will be the id if the user tapped on the notification itself when buttons were present.\n - __`BOOL` _isActive___ - True if user is currently using your app when the notification came in.\n \n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"self.oneSignal = [[OneSignal alloc]\\n initWithLaunchOptions:launchOptions\\n appId:@\\\"b2f7f966-d8cc-11e4-bed1-df8f05be55ba\\\"\\n handleNotification:^(NSString* message, NSDictionary* additionalData, BOOL isActive) {\\n NSLog(@\\\"OneSignal Notification opened:\\\\nMessage: %@\\\", message);\\n \\n if (additionalData) {\\n NSLog(@\\\"additionalData: %@\\\", additionalData);\\n \\n // Check for and read any custom values you added to the notification\\n // This done with the \\\"Additional Data\\\" section the dashboard.\\n // OR setting the 'data' field on our REST API.\\n NSString* customKey = additionalData[@\\\"customKey\\\"];\\n if (customKey)\\n NSLog(@\\\"customKey: %@\\\", customKey);\\n }\\n}];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"_ = OneSignal(launchOptions: launchOptions, appId: \\\"b2f7f966-d8cc-11e4-bed1-df8f05be55ba\\\") { (message, additionalData, isActive) in\\n NSLog(\\\"OneSignal Notification opened:\\\\nMessage: %@\\\", message)\\n \\n if additionalData != nil {\\n NSLog(\\\"additionalData: %@\\\", additionalData)\\n // Check for and read any custom values you added to the notification\\n // This done with the \\\"Additonal Data\\\" section the dashbaord.\\n // OR setting the 'data' field on our REST API.\\n if let customKey = additionalData[\\\"customKey\\\"] as! String? {\\n NSLog(\\\"customKey: %@\\\", customKey)\\n }\\n }\\n}\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n#### OneSignalResultSuccessBlock\nBlock for OneSignal methods that gets called when the OneSignal server is contacted successfully.\n\n - __Parameters__\n - __`NSDictionary` _result___ - The resulting JSON response from the OneSignal server.\n \n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal getTags:^(NSDictionary* result) {\\n\\tNSLog(@\\\"%@\\\", result);\\n}];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.getTags({ (tags) in\\n\\tNSLog(\\\"%@\\\", tags)\\n})\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]\n#### OneSignalFailureBlock\nBlock for OneSignal methods that gets called when the OneSignal server can't be contacted or there was a error in the response.\n\n - __Parameters__\n - __`NSError*` _error___ - errorWithDomain == \"OneSignalError\", code == HTTP error code from the OneSignal server, userInfo == JSON OneSignal responded with.\n \n \n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[self.oneSignal registerDeviceToken:deviceToken onSuccess:^(NSDictionary* results) {\\n\\tNSLog(@\\\"Device Registered with OneSignal.\\\");\\n} onFailure:^(NSError* error) {\\n\\tNSLog(@\\\"Error in OneSignal Registration: %@\\\", error);\\n}];\",\n \"language\": \"objectivec\"\n }\n ]\n}\n[/block]\n#### OneSignalIdsAvailableBlock\nLets you retrieve the OneSignal user id and device token. Your block is called after the device is successfully registered with OneSignal.\n\n - __Parameters__\n - __`NSString*` _userId___ - OneSignal userId is a UUID formatted string.(_unique per device per app_)\n - __`NSString*` _pushToken___ - pushToken is a Apple assigned identifier(_unique per device per app_).\n[block:callout]\n{\n \"type\": \"warning\",\n \"title\": \"NOTE\",\n \"body\": \"Might be `nil` if the user does not accept push notifications for your app or there was a connection issue.\"\n}\n[/block]\n\n[block:callout]\n{\n \"type\": \"warning\",\n \"title\": \"NOTE 2\",\n \"body\": \"If you disable auto register or the user waits over 30 seconds to say yes to the system prompt then your call back will be called twice. First with just the userId field and then a 2nd time to with the push token included.\"\n}\n[/block]\n- __Example__\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"[oneSignal IdsAvailable:^(NSString* userId, NSString* pushToken) {\\n\\tNSLog(@\\\"UserId:%@\\\", userId);\\n\\tif (pushToken != nil)\\n\\t\\tNSLog(@\\\"pushToken:\\\", pushToken);\\n}];\",\n \"language\": \"objectivec\"\n },\n {\n \"code\": \"oneSignal.IdsAvailable({ (userId, pushToken) in\\n\\tNSLog(\\\"UserId:%@\\\", userId)\\n if (pushToken != nil) {\\n \\tNSLog(\\\"pushToken:%@\\\", pushToken)\\n }\\n})\",\n \"language\": \"swift\",\n \"name\": \"Swift\"\n }\n ]\n}\n[/block]","excerpt":"","slug":"ios-sdk-api","type":"basic","title":"API Reference"}