Comprehensive reference of OneSignal’s SDK methods
setLogLevel
MethodParameters | Type | Description |
---|---|---|
logLevel | LOG_LEVEL | Sets the logging level to print to the Android LogCat log or Xcode log. |
visualLevel | LOG_LEVEL | Sets the logging level to show as alert dialogs. |
subscription_id
(formerly calledplayer_id
). A single user can have multiple subscription_id
records based on how many devices, email addresses, and phone numbers they use to interact with your app/site.
You can combine subscription_id
records in OneSignal under a unique User Id called the external_id
.
See the External User Ids guide for more details.
If you have a backend server, we strongly recommend using Identity Verification with your users. Your backend can generate an identifier authentication token and send it to your site.
The OneSignal SDK setExternalUserId
method should be called when the user logs into the app/site and within the callback of the setEmail
and setSMSNumber
methods to link the records together.
external_user_id
and Data Tags.If setting external_user_id
through the Edit device API Endpoint, then use the same endpoint to remove the external_user_id
upon the user logging out of the app.The removeExternalUserId
method will not work unless the external_user_id
is set first with the setExternalUserId
method on Android.This is only applicable on the OneSignal Android Mobile App SDKs.key : value
pairs of string or number data you set on users based on events or user data of your choosing. See Data Tags Overview for more details on what tags are used for.
See Data Tag Implementation for SDK Method details.
addPermissionObserver
or addSubscriptionObserver
to react to changes. For example, update your server when the user becomes subscribed or unsubscribed, and to get the OneSignal Subscription Id.
If you need to store the OneSignal Subscription Id within your backend, you can make a REST API call directly from the observer’s callback. The OneSignal observer fires only when there is a change (including not firing even if the app has been restarted). This helps ensure you are not making unnecessary network calls to your backend on each app restart if nothing changed.
null
or no available. Use to load your UI to the correct state. Such as showing a toggle button to enable notifications.Name | Status |
---|---|
0 - Not Determined | The user hasn’t yet made a choice about whether the app is allowed to schedule notifications. |
1 - Denied | The application is not authorized to post user notifications. |
2 - Authorized | The application is authorized to post user notifications. |
3 - Provisional | The application is provisionally authorized to post noninterruptive user notifications. |
4 - Ephemeral | For App Clips. The app is authorized to schedule or receive notifications for a limited amount of time. |
onOSPermissionChanged
method will be fired on the passed-in object when a notification permission setting changes.
This includes the following events:
onOSPermissionChanged
method, which provides what the value was (“from”) and what the value is now (“to”).
Any object implementing the OSPermissionObserver
and/or the OSSubscriptionObserver
protocols can be added as an observer. You can call removePermissionObserver
to remove any existing listeners.
OneSignal uses a weak reference to the observer to prevent leaks.
subscriptionChange
Event.addEmailSubscriptionObserver
Method.addSMSSubscriptionObserver
Method.onOSSubscriptionChanged
method will be fired on the passed-in object when a notification subscription property changes.
This includes the following events:
OneSignal.disablePush
is calledonOSSubscriptionChanged
method which provides what the value was (“from”) and what the value is now (“to”).
Any object implementing the OSPermissionObserver
and/or the OSSubscriptionObserver
protocols can be added as an observer. You can call removePermissionObserver
to remove any existing listeners.
OneSignal uses a weak reference to the observer to prevent leaks.
setLanguage
MethodsetRequiresUserPrivacyConsent
Methodtrue
, your application will need to call provideUserConsent(true)
before the OneSignal SDK gets fully initialized. Until this happens, you can continue to call methods (such as sendTags()
), but nothing will happen.
provideUserConsent(true)
, the SDK will not fully initialize, and will not send any data to OneSignal.
setLocationShared
MethodinitWithLaunchOptions
on iOS.
isLocationShared
MethodpromptLocation
MethodAndroidManifest.xml
and/or info.plist
.
promptForPushNotifications
method.postNotification
Methodinclude_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.See the Create notification REST API POST call for a list of all possible options.Parameter | Type | Description |
---|---|---|
parameters | JSONObject, NSDictionary*, JSONString, Callback | Contains notification options, see our Create notification POST call for all options. |
clearOneSignalNotifications
MethoddisablePush
MethodEnableVibrate
& EnableSound
MethodsunsubscribeWhenNotificationsAreDisabled
MethodsetLaunchURLsInApp
Method (iOS)true
to launch all notifications with a URL in the app instead of the default web browser. Make sure to call setLaunchURLsInApp
before the setAppId
call.
Parameter Type | Description |
---|---|
Bool | Boolean indicates if launch URLs should be opened in safari or within the application. |
activityId
with a live activity temporary push token
on OneSignal’s server. The activityId is then used with the OneSignal REST API to update one or multiple Live Activities at one time.
Parameter | Type | Description |
---|---|---|
activityId | String | A customer defined identifier that gets assisted with the temporary push token on OneSignal’s server. When the customer uses the update endpoint they will send this activityId to specify which push tokens they would like to update. NOTE: activityId cannot contain any / (forward slash) characters. |
token | String | A Live Activity temporary push token. |
enterliveActivity
usage with context:
activityId
with a Live Activity temporary push token
on OneSignal’s server.
exitliveActivity
usage