Deprecated OneSignal-iOS-SDK 2.x.x version
This is for the older 2.x.x version of the API. Please see [the latest API reference here](🔗)
Parameter | Data Type | Description |
**Debugging** | | |
[setLogLevel](🔗) | Method | Enable logging to help debug OneSignal implementation |
**Initialization** | | |
[initWithLaunchOptions](🔗) | Method | Initialize OneSignal |
[inFocusDisplayType](🔗) | Property | Setting to control how OneSignal notifications will be shown when one is received while your app is in focus. |
**Settings** | | |
`kOSSettingsKeyAutoPrompt ` | Key | Automatically Prompt Users to Enable Notifications. See [iOS SDK Setup](🔗) for code examples.
`true ` (<span class="label-all label-default">Default</span>) - automatically prompts for notifications permissions.
`false ` - disables auto prompt.
<span class="label-all label-recommended">Recommended</span>: Set to `false ` and follow [iOS Push Opt-In Prompt](🔗). |
`kOSSettingsKeyInAppLaunchURL ` | Key | Open URLs in In-App Safari Window or Safari app. See [iOS SDK Setup](🔗) for code examples.
`true ` (<span class="label-all label-default">Default</span>) - Open all URLs with a in-app WebView window.
`false ` - Launches Safari with the URL OR other app (if deep linked or custom URL scheme passed). |
**Handling Notifications** | | |
[handleNotificationReceived](🔗) | Method | Called when the app receives a notification while in focus only. |
[handleNotificationAction](🔗) | Method | Called when the user opens or taps an action on a notification. |
**Privacy** | | |
[setRequiresUserPrivacyConsent](🔗) | Method | Delays initialization of the SDK until the user provides privacy consent |
[consentGranted](🔗) | Method | Tells the SDK that the user has provided privacy consent (if required) |
**iOS Prompting** | | |
[promptForPushNotificationsWithUserResponse](🔗) | Method | Prompt the user for notification permissions. Callback fires as soon as the user accepts or declines notifications.
Must set `kOSSettingsKeyAutoPrompt ` to `false ` when calling [initWithLaunchOptions](🔗).
<span class="label-all label-recommended">Recommended</span>: Set to `false ` and follow [iOS Push Opt-In Prompt](🔗). |
[presentAppSettings](🔗) | Method | Presents the iOS Settings for your application |
**User Status** | | [More Details](🔗) |
[getPermissionSubscriptionState](🔗) | Method | Get the current notification and permission state. Returns a [`OSPermissionSubscriptionState ` type](🔗). |
[addPermissionObserver](🔗) | Method | Observer method for Current Device Record's Permission status changes. |
[addSubscriptionObserver](🔗) | Method | Observer method for Current Device Record's Subscription status changes. |
[setSubscription](🔗) | Method | Disable OneSignal from sending notifications to current device. |
**External User IDs** | | |
[setExternalUserId](🔗) | Method | Allows you to use your own system's user ID's to send push notifications to your users. To tie a user to a given user ID, you can use this method. |
[removeExternalUserId](🔗) | Method | Removes whatever was set as the current user's external user ID. |
**Tagging** | | |
[getTags](🔗) | Method | View Tags from current device record. |
[sendTag](🔗) | Method | Add a single [Data Tag](🔗) to current device record. |
[sendTags](🔗) | Method | Add multiple [Data Tags](🔗) to current device record. |
[deleteTag](🔗) | Method | Delete a Tag from current device record. |
[deleteTags](🔗) | Method | Delete multiple Tags from current device record. |
**Location Data** | | |
[setLocationShared](🔗) | Method | Disable or Enable SDK location collection. See [Handling Personal Data](🔗). |
[promptLocation](🔗) | Method | Prompt Users for Location <span class="label-all label-no">Not Recommended</span> <span class="label-all label-recommended">Recommended</span>: Use In-App Message [Location Opt-In Prompt](🔗). |
**Sending Notifications** | | |
[postNotification](🔗) | Method | Send or schedule a notification to a OneSignal Player ID. |
[clearOneSignalNotifications](🔗) | Method | Delete all app notifications |
**In-App Messaging** | | |
[addTrigger](🔗) | Method | Add a trigger, may show an In-App Message if its triggers conditions were met. |
[addTriggers](🔗) | Method | Add a map of triggers, may show an In-App Message if its triggers conditions were met. |
[removeTriggerForKey](🔗) | Method | Removes a list of triggers based on a collection of keys, may show an In-App Message if its triggers conditions were met. |
[getTriggerValueForKey](🔗) | Method | Gets a trigger value for a provided trigger key. |
[pauseInAppMessages](🔗) | Method | Allows you to temporarily pause all In App Messages. |
[setInAppMessageClickHandler](🔗) | Method | Sets an In App Message opened block |
**Email** | | |
[setEmail](🔗) | Method | Set user's email. Creates a new user record for the email address. Use `sendTag ` if you want to update a push user record with the email. |
[logoutEmail](🔗) | Method | Log user out to dissociate email from device |
[addEmailSubscriptionObserver](🔗) | Method | Observer for subscription changes to email |
**Notification Objects** | | |
[OSNotificationOpenedResult](🔗) | Object | Information returned from a notification the user received. |
[OSNotification](🔗) | Object | Represents a received push notification |
[OSNotificationAction](🔗) | Object | How user opened notification |
[OSNotificationPayload](🔗) | Object | Data that comes with a notification |
## Initialization
### `initWithLaunchOptions
`
<div class="label-all label-type">Method</div>
Must be called from `didFinishLaunchingWithOptions
` in `AppDelegate.m
`.
Parameter | Type | Description |
`launchOptions ` | NSDictionary* | <span class="label-all label-required">Required</span> launchOptions that you received from `didFinishLaunchingWithOptions ` |
`appId ` | NSString* | <span class="label-all label-required">Required</span> Your OneSignal app id, available in <a class="dash-link dash-settings" href="/docs/accounts-and-keys">Keys & IDs</a> |
`callback ` | [OSHandleNotificationReceivedBlock](🔗) | Function to be called when a notification is received |
`callback ` | [OSHandleNotificationActionBlock](🔗) | Function to be called when a user reacts to a notification received |
`settings ` | NSDictionary* | Customization settings to change OneSignal's default behavior |
## Handling Notifications
### `OSHandleNotificationReceivedBlock
`
<div class="label-all label-type">Callback</div>
Called when the app receives a notification while in focus only. Note: If you need this to be called when your app is in the background, set `content_available
` to `true
` when you create your notification. The "force-quit" state (i.e app was swiped away) is limited due to iOS restrictions.
Parameter | Type | Description |
`notification ` | [OSNotification](🔗) | The OneSignal Notification Object |
### `OSHandleNotificationActionBlock
`
<div class="label-all label-type">Callback</div>
Called when the user opens or taps an action on a notification.
Parameter | Type | Description |
`result ` | [OSNotificationOpenedResult](🔗) | Data available within the OneSignal Notification Object when clicking the notification. |
#### `OSNotificationOpenedResult
`
<div class="label-all label-type">Interface Element</div>
The information returned from a notification the user received. Resulting class passed to [OSHandleNotificationActionBlock](🔗).
Class Properties |
`notification `([OSNotification](🔗)); |
`action `([OSNotificationAction](🔗)); |
### `OSNotification
`
<div class="label-all label-type">Interface Element</div>
The notification the user received.
Class Properties | Column Title |
`payload `([OSNotificationPayload](🔗)); | |
`displayType `([OSNotificationDisplayType](🔗)); | |
`shown `(_BOOL_); | True when the user was able to see the notification. False when app is in focus and in-app alerts are disabled, or the remote notification is silent. |
`silentNotification `(_BOOL_); | True when the received notification is silent. Silent means there is no alert, sound, or badge payload in the APS dictionary. Requires remote-notification within UIBackgroundModes array of the Info.plist |
#### `OSNotificationAction
`
<div class="label-all label-type">Interface Element</div>
The action the user took on the notification.
Class Properties | Column Title |
`actionID `(_NSString_); | The ID associated with the button tapped. NULL when the actionType is NotificationTapped or InAppAlertClosed. |
`type `([OSNotificationActionType](🔗)); | The type of the notification action. |
#### `OSNotificationActionType
`
<div class="label-all label-type">Interface Element</div>
The action type (_NSUInteger Enum_) associated to an OSNotificationAction object.
NSUInteger Enum Properties |
`Opened ` |
`ActionTaken ` |
#### `OSNotificationDisplayType
`
<div class="label-all label-type">Interface Element</div>
The way in which a notification was displayed to the user (_NSUInteger Enum_).
NSUInteger Enum Properties | Raw Value | Column Title |
`Notification ` | 2 | iOS native notification display. |
`InAppAlert ` | 1 | Default UIAlertView display (note this is not an In-App Message) |
`None ` | 0 | Notification is silent, or app is in focus but InAppAlertNotifications are disabled. |
### `OSNotificationPayload
`
<div class="label-all label-type">Interface Element</div>
Contents and settings of the notification the user received.
Class Properties | Column Title |
`notificationID ` (_NSString_); | OneSignal notification UUID |
`contentAvailable `(_BOOL_); | Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed `application:didReceiveRemoteNotification:fetchCompletionHandler: ` is called. |
`badge `(_NSInteger_); | The badge number assigned to the application icon |
`sound `(_NSString_); | The sound parameter passed to the notification. By default set to `UILocalNotificationDefaultSoundName `. [Read more about custom sounds](🔗) |
`title `(_NSString_); | Title text of the notification |
`body ` (_NSString_); | Body text of the notification |
`subtitle ` (_NSString_); | <span class="label-all label-ios">iOS 10+</span> - subtitle text of the notification |
`launchURL `(_NSString_); | Web address to launch within the app via a `UIWebView ` |
`additionalData `(_NSDictionary_); | Additional Data add to the notification by you |
`attachments `(_NSDictionary_); | <span class="label-all label-ios">iOS 10+</span> - Attachments sent as part of the rich notification |
`actionButtons `(_NSArray_); | Action buttons set on the notification |
`rawPayload `(_NSDictionary_); | Holds the raw APS payload received |
`parseWithApns ` (Method); | Parses an APS push payload into a OSNotificationPayload object. Useful to call from your NotificationServiceExtension when the `didReceiveNotificationRequest:withContentHandler: ` method fires. |
### `presentAppSettings
`
<div class="label-all label-type">Method</div>
iOS does not allow you to prompt for push notification permissions a second time if the user has denied it the first time. This method will open the iOS Settings page for your app that they can then select notifications option to enable them.
Deprecation Warning
`
presentAppSettings
` is deprecated in OneSignal iOS SDK Major Release 3.0+[Use `
promptForPushNotifications
` with `fallbackToSettings
` set to true instead.](🔗)
## Sending Notifications
### `postNotification
`
<div class="label-all label-type">Method</div>
Allows you to send notifications from user to user or schedule ones in the future to be delivered to the current device.
See the [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.
Parameter | Type | Description |
`parameters ` | NSDictionary* | Dictionary of notification options, see our [Create notification](🔗) POST call for all options. |
`onSuccess(Optional) ` | OneSignalResultSuccessBlock | Called if there were no errors sending the notification |
`onFailure(Optional) ` | OneSignalFailureBlock | Called if there was an error |
### `ClearOneSignalNotifications
`
<div class="label-all label-type">Method</div>
iOS provides a standard way to clear notifications by clearing badge count, thus there is no specific OneSignal API call for clearing notifications.