Hey! These docs are for version 7.0, which is no longer officially supported. Click here for the latest version, 9.0!


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](🔗)

ParameterData TypeDescription
**Debugging**

[setLogLevel](🔗)MethodEnable logging to help debug OneSignal implementation
**Initialization**

[initWithLaunchOptions](🔗)MethodInitialize OneSignal
[inFocusDisplayType](🔗)PropertySetting to control how OneSignal notifications will be shown when one is received while your app is in focus.
**Settings**

`kOSSettingsKeyAutoPrompt`KeyAutomatically 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`KeyOpen 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](🔗)MethodCalled when the app receives a notification while in focus only.
[handleNotificationAction](🔗)MethodCalled when the user opens or taps an action on a notification.
**Privacy**

[setRequiresUserPrivacyConsent](🔗)MethodDelays initialization of the SDK until the user provides privacy consent
[consentGranted](🔗)MethodTells the SDK that the user has provided privacy consent (if required)
**iOS Prompting**

[promptForPushNotificationsWithUserResponse](🔗)MethodPrompt 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](🔗)MethodPresents the iOS Settings for your application
**User Status**
[More Details](🔗)
[getPermissionSubscriptionState](🔗)MethodGet the current notification and permission state. Returns a [`OSPermissionSubscriptionState` type](🔗).
[addPermissionObserver](🔗)MethodObserver method for Current Device Record's Permission status changes.
[addSubscriptionObserver](🔗)MethodObserver method for Current Device Record's Subscription status changes.
[setSubscription](🔗)MethodDisable OneSignal from sending notifications to current device.
**External User IDs**

[setExternalUserId](🔗)MethodAllows 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](🔗)MethodRemoves whatever was set as the current user's external user ID.
**Tagging**

[getTags](🔗)MethodView Tags from current device record.
[sendTag](🔗)MethodAdd a single [Data Tag](🔗) to current device record.
[sendTags](🔗)MethodAdd multiple [Data Tags](🔗) to current device record.
[deleteTag](🔗)MethodDelete a Tag from current device record.
[deleteTags](🔗)MethodDelete multiple Tags from current device record.
**Location Data**

[setLocationShared](🔗)MethodDisable or Enable SDK location collection. See [Handling Personal Data](🔗).
[promptLocation](🔗)MethodPrompt 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](🔗)MethodSend or schedule a notification to a OneSignal Player ID.
[clearOneSignalNotifications](🔗)MethodDelete all app notifications
**In-App Messaging** 

[addTrigger](🔗)MethodAdd a trigger, may show an In-App Message if its triggers conditions were met.
[addTriggers](🔗)MethodAdd a map of triggers, may show an In-App Message if its triggers conditions were met.
[removeTriggerForKey](🔗)MethodRemoves a list of triggers based on a collection of keys, may show an In-App Message if its triggers conditions were met.
[getTriggerValueForKey](🔗)MethodGets a trigger value for a provided trigger key.
[pauseInAppMessages](🔗)MethodAllows you to temporarily pause all In App Messages.
[setInAppMessageClickHandler](🔗)MethodSets an In App Message opened block
**Email** 

[setEmail](🔗)MethodSet 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](🔗)MethodLog user out to dissociate email from device
[addEmailSubscriptionObserver](🔗)MethodObserver for subscription changes to email
**Notification Objects**

[OSNotificationOpenedResult](🔗)ObjectInformation returned from a notification the user received.
[OSNotification](🔗)ObjectRepresents a received push notification
[OSNotificationAction](🔗)ObjectHow user opened notification
[OSNotificationPayload](🔗)ObjectData that comes with a notification

## Initialization

### `initWithLaunchOptions`

<div class="label-all label-type">Method</div>

Must be called from `didFinishLaunchingWithOptions` in `AppDelegate.m`.

ParameterTypeDescription
`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.

ParameterTypeDescription
`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.

ParameterTypeDescription
`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 PropertiesColumn 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 PropertiesColumn 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 PropertiesRaw ValueColumn Title
`Notification`2iOS native notification display.
`InAppAlert`1Default UIAlertView display (note this is not an In-App Message)
`None`0Notification 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 PropertiesColumn 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.

ParameterTypeDescription
`parameters`NSDictionary*Dictionary of notification options, see our [Create notification](🔗) POST call for all options.
`onSuccess(Optional)`OneSignalResultSuccessBlockCalled if there were no errors sending the notification
`onFailure(Optional)`OneSignalFailureBlockCalled 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.