Setup & debugging
These methods are a reference for integrating the OneSignal SDK into your app. For full platform-specific setup instructions, see Mobile SDK setup.initialize()
Initializes the OneSignal SDK. This should be called during application startup. The ONESIGNAL_APP_ID can be found in Keys & IDs.
If you want to delay initialization of the OneSignal SDK, we recommend using our Privacy methods.
setLogLevel()
Set the logging to print additional logs to Android LogCat or Xcode logs.
Call this before initializing OneSignal. See Getting a Debug Log for more details.
setAlertLevel()
Sets the logging level to show as alert dialogs in your app. Make sure to remove this before submitting to the app store.
User identity & properties
When users open your app, OneSignal automatically creates a OneSignal ID (user-level ID) and a Subscription ID (device-level ID). You can associate multiple Subscriptions (e.g., devices, emails, phone numbers) with a single user by callinglogin() with your unique user identifier.
See Users and Subscriptions for more details.
login(external_id)
Sets the current user context to the provided external_id. This links the current device (mobile Subscription) to a known user and unifies all future data under a single onesignal_id. Use this method only for identified users (for example, after login or account restore). For anonymous users, do not call login. Instead, track them using their automatically assigned onesignal_id (see getOnesignalId()).
What happens when you call login(external_id)
The SDK behaves differently depending on whether the external_id already exists within the OneSignal app.
If the external_id already exists:
- The SDK switches to that existing user.
- You may see a
409 Conflicterror. This is an expected, innocuous error indicating that the External ID already exists within the OneSignal app and can be ignored.
- You may see a
- The current
onesignal_idis discarded and the existingonesignal_idfor that user is loaded. - The current device (mobile Subscription) is linked to the existing user.
- Anonymous data collected before login is not merged and is discarded. This includes tags, session data, email/SMS Subscriptions, and other local user properties.
external_id does not exist:
- A new user is created using the current
onesignal_id. - All data collected while the user was anonymous is retained.
- The device (mobile Subscription) becomes linked to this new user.
- The SDK automatically retries the login request on network failures or server errors.
- You do not need to implement your own retry logic.
- Call
login(external_id)every time the app starts once you know the user’s ID (for example, after sign-in or session restore). - Call it again whenever the signed-in user changes (account switch).
- Do not call
loginbefore you have a stable, known user identifier.
logout()
Unlinks the current user from the mobile Subscription.
- Removes the
external_idfrom the current mobile Subscription. Does not remove theexternal_idfrom other Subscriptions. - Resets the
onesignal_idto a new anonymous user. - Any new data (e.g tags, Subscriptions, session data, etc.) will now be set on the new anonymous user until they are identified with the
loginmethod.
Use this when a user signs out of your app and you do not want to send targeted transactional messages to the device anymore.
getOnesignalId()
Retrieves the current user’s onesignal_id stored locally on the device. This value represents the active user context (OneSignal’s User ID) and can change over time — for example, when you call login(external_id) or when the SDK initializes. If called too early, this method may return null.
This value is not the Subscription ID which is used to identify the device aka mobile Subscription (see User.pushSubscription.id).
When onesignal_id is available:
- After the OneSignal SDK finishes initializing
- After a user is identified with
login(external_id) - After switching users or restoring a session
addObserver() instead of polling.
Common use cases:
In most cases, you will want to use your own External ID set via the login method. However, there are some cases where you may want to use the onesignal_id directly.
- Tracking anonymous users before an External ID is set
- Storing the OneSignal ID in your backend for support or debugging
- Correlating OneSignal users with internal logs
- Displaying the ID for troubleshooting or QA
getExternalId()
Retrieve the current user’s External ID saved locally on the device. May be null if not set via the login method or called before user state is initialized. Instead, use User State addObserver() to listen for user state changes.
addEventListener() User State
Listen for changes in the user context (e.g., login, logout, ID assignment).
addAlias(), addAliases(), removeAlias(), removeAliases()
Aliases are alternative identifiers (like usernames or CRM IDs).
- Set
external_idwithlogin()before adding aliases. Aliases added to subscriptions withoutexternal_idwill not sync across multiple subscriptions. - See Aliases for details.
setLanguage()
Overrides the auto-detected language of the user. Use ISO 639-1 language code.
Custom events
Trigger Journeys and Wait Until step activation via a custom event.Custom events are still in beta and require the following version of the SDK to be triggered from your app:
- iOS native SDK, available starting
5.4.0-alpha-01 - Android native SDK, available starting
5.3.0-alpha-01 - React-native SDK, available starting
5.3.0-beta-01 - Flutter SDK, available starting
5.4.0-beta-01 - Unity SDK, available starting
5.2.0-beta-01
name- Required. The name of the event as a string.properties- Optional. Key-value pairs to add to the event. The properties dictionary or map must be serializable into a valid JSON Object. Supports nested values.
os_sdk that will be available to consume. For example, to target events by device type, you would access os_sdk.device_type.
json
trackEvent()
See Custom Events for more details.
Data tags
Tags are customkey : value pairs of string data you set on users based on events or user properties. See Data Tags for more details.
addTag(), addTags()
Set a single or multiple tags on the current user.
- Values will be replaced if the key already exists.
- Exceeding your plan’s tag limit will cause the operations to fail silently.
removeTag(), removeTags()
Delete a single or multiple tags from the current user.
getTags()
Returns the local copy of the user’s tags. Tags are updated from the server during login() or new app sessions.
Privacy
setConsentRequired()
Enforces user consent before data collection begins. Must be called before initializing the SDK.
setConsentGiven()
Grants or revokes user consent for data collection. Without consent, no data is sent to OneSignal and no subscription is created.
- If
setConsentRequired()istrue, our SDK will not be fully enabled untilsetConsentGivenis called withtrue. - If
setConsentGivenis set totrueand a Subscription is created, then later it is set tofalse, that Subscription will no longer receive updates. The current data for that Subscription remains unchanged untilsetConsentGivenis set totrueagain. - If you want to delete the User and/or Subscription data, use our Delete user or Delete subscription APIs.
Location
Tracking location points requires 3 steps:- Add location tracking permissions and dependencies to your app.
- iOS: Choosing the Location Services Authorization to Request developer guide
- Android: Request location permissions developer guide
LocationManager.startGetLocation: not possible, no location dependency foundCheck your App’s dependencies. A common solutions is in you
app/build.gradle add: implementation 'com.google.android.gms:play-services-location:21.0.1'
- Enable your app to share location with OneSignal using the
Location.setShared()method. - Request permission from the user for location tracking with the
Location.requestPermissionmethod or use in-app messages.
setShared() Location
Use this method to allow our SDK to start tracking the Subscription’s latitude and longitude. Make sure you set the proper location permissions in your app first.
requestPermission() Location
Use this method to display the system-level location permission prompt to your users or instead use in-app messages. Make sure you set the proper location permissions in your app and enabled your app to share location with OneSignal.
Subscriptions
A Subscription represents a single messaging channel instance (for example, a mobile device) and has a unique Subscription ID (OneSignal’s device-level ID). A user can have multiple Subscriptions across devices and platforms. See Subscriptions for more details.User.pushSubscription.id
Retrieves the mobile Subscription ID for the current device, stored locally by the SDK.
This ID uniquely identifies this specific device’s push channel, not the user. It is commonly used when associating devices with your backend or debugging delivery issues.
If called before the Subscription is created or restored, this value may be null.
To reliably detect when the mobile Subscription ID becomes available or changes, use the push Subscription observer.
User.pushSubscription.token
Returns the current push subscription token. May return null if called too early. Its recommended to get this data within the subscription observer to react to changes.
addObserver() Push Subscription Changes
Use this method to respond to push subscription changes like:
- The device receives a new push token from Google (FCM) or Apple (APNs)
- OneSignal assigns a subscription ID
- The
optedInvalue changes (e.g. calledoptIn()oroptOut()) - The user toggles push permission in system settings, then opens the app
onPushSubscriptionChange event. Your listener receives a state object with the previous and current values so you can detect exactly what changed.
To stop listening for updates, call the associated removeObserver() or removeEventListener() method.
optOut(), optIn(), optedIn
Control the subscription status (subscribed or unsubscribed) of the current push Subscription. Use these methods to control the push subscription status within your app. Common use cases: 1) Prevent push from being sent to users that log out. 2) Implement a notification preference center within your app.
optOut(): Sets the current push subscription status to unsubscribed (even if the user has a valid push token).optIn(): Does one of three actions:- If the Subscription has a valid push token, it sets the current push subscription status to
subscribed. - If the Subscription does not have a valid push token, it displays the push permission prompt.
- If the push permission prompt has been displayed more than the operating system’s limit (once iOS, twice Android), it displays the fallback prompt.
- If the Subscription has a valid push token, it sets the current push subscription status to

Fallback to settings prompt
optedIn: Returnstrueif the current push subscription status is subscribed, otherwisefalse. If the push token is valid butoptOut()was called, this will returnfalse.
addEmail(), removeEmail()
Adds or removes an email Subscription (email address) for the current user.
These methods are compatible with Identity Verification.
When you call addEmail(email):
- The email address becomes an email Subscription for the current user.
- The email may be created or reassigned.
- The same email address cannot exist multiple times in the same OneSignal app. If you see duplicate email addresses, check your REST API requests and contact support if needed.
| Status code | Meaning |
|---|---|
| 200 OK | The email Subscription already belongs to the current user. No changes were made. |
| 201 Created | A new email Subscription was created and linked to the user. |
| 202 Accepted | The email Subscription already existed in the app and was moved to the current user. |
removeEmail(email):
- The email Subscription is removed from the current user.
- The current External ID is removed from the email Subscription.
- A new OneSignal ID is assigned to the email Subscription.
- Other Subscriptions (push, SMS, other emails) remain unaffected.
- Call
login()first, then calladdEmail(). Otherwise, the email may be attached to an anonymous user. - Use a stable, verified email address.
- Follow Email reputation best practices.
addSms(), removeSms()
Adds or removes an SMS Subscription (phone number) for the current user. Phone numbers must be provided in E.164 format (for example, +15551234567).
These methods are compatible with Identity Verification.
When you call addSms(phoneNumber):
- The phone number becomes an SMS Subscription for the current user.
- The number may be created or reassigned.
- The same phone number cannot exist multiple times in the same OneSignal app. If you see duplicate phone numbers, check your REST API requests and contact support if needed.
| Status code | Meaning |
|---|---|
| 200 OK | The SMS Subscription already belongs to the current user. No changes were made. |
| 201 Created | A new SMS Subscription was created and linked to the user. |
| 202 Accepted | The SMS Subscription already existed in the app and was moved to the current user. |
removeSms(phoneNumber):
- The SMS Subscription is removed from the current user.
- The current External ID is removed from the SMS Subscription.
- A new OneSignal ID is assigned to the SMS Subscription.
- Other Subscriptions (push, email, other SMS) remain unaffected.
- Call
login()first, then calladdSms(). Otherwise, the SMS Subscription may be attached to an anonymous user. - Always validate and normalize phone numbers to E.164 format before sending.
- Follow SMS Registration Requirements.
Push permissions
requestPermission(fallbackToSettings) Push
Shows the native system prompt asking the user for push notification permission. Optionally enable a fallback prompt that links to the settings app.
fallbackToSettings: Iftrue, the fallback prompt will be displayed if the user denied push permissions more than the operating system’s limit (once iOS, twice Android).

Fallback-to-settings prompt when permission is blocked
See Prompt for Push Permissions for more information.
addPermissionObserver() Push
Use this method to track push permission changes like:
- The notification permission prompt is displayed to the user.
- The user accepts or declines the permission prompt.
- The user enables or disables notifications for your app in the device’s app settings and then returns to your app.
onOSPermissionChanged event. Your listener receives a state object with the from and to values so you can detect exactly what changed.
To stop listening for updates, call the associated removePermissionObserver() method.
getPermission(), getCanRequestPermission()
getPermission() returns the current push permission status at the app-level. It does not consider the OneSignal-level subscription status if you changed it via optOut() or the enabled parameter in the Users and Subscriptions APIs. Instead of using getPermission(), we recommend using the Push Permission Observer to track changes in the device’s notification permission status while the app is running or the Push Subscription Observer to track changes in the push subscription status.
getCanRequestPermission() returns whether attempting to request permission will result in a prompt being displayed to the user. If false, the user has already denied permission and can either be shown the fallback prompt or no prompt at all. See Prompt for push permissions for more information.
permissionNative iOS
Returns an enum for the native permission of the iOS device. It will be one of:
0= NotDetermined1= Denied2= Authorized3= Provisional (only available in iOS 12+)4= Ephemeral (only available in iOS 14+)
Push notification events
addClickListener() Push
Set a callback that runs when a user clicks a push notification that opens the app.
The app’s activity or scene is already launched by the time this event fires. Use this handler to perform any custom logic — do not relaunch or duplicate app navigation manually.
Use removeClickListener() or removeEventListener() to stop listening when the handler is no longer needed.
addForegroundLifecycleListener() Push
Allows you to intercept and control how notifications behave when the app is in the foreground.
By default, OneSignal automatically displays the notification. You can override this behavior using event.preventDefault() to:
- Suppress the notification
- Customize it
- Delay display for async logic (e.g., fetch user state, log events)
event.notification.display() to manually show it later.
This runs after Notification Service Extensions, which modify the payload before display.
removeForegroundLifecycleListener() or removeEventListener() to stop listening when the handler is no longer needed.
clearAllNotifications()
Removes all OneSignal notifications from the Notification Shade. Use instead of Android’s android.app.NotificationManager.cancel. Otherwise, the notifications will be restored when your app is restarted.
removeNotification() Android
Cancel a single notification based on its Android notification ID.
Use instead of Android’s android.app.NotificationManager.cancel. Otherwise, the notification will be restored when your app is restarted.
removeGroupedNotifications() Android
Cancel a group of OneSignal notifications with the provided group key. Grouping notifications is a OneSignal concept. There is no android.app.NotificationManager equivalent.
In-App Messages
In-app messages do not require any code; however, the SDK enables you to customize when messages are presented and handle lifecycle events.addTrigger(), addTriggers()
Decide when to display an In-App Message based on a single or multiple triggers. See Triggers for more information.
Triggers are not persisted to the backend. They only exist on the local device and apply to the current user.
removeTrigger(), removeTriggers(), clearTriggers()
Remove a single, multiple, or all triggers with the provided key from the current user.
paused
Prevent In-app messages from being displayed to the user. When set to true, no in-app messages will be presented. When set to false, any messages the user qualifies for will be presented to them at the appropriate time.
addLifecycleListener()
Respond to or track In-App Messages being displayed and dismissed.
addClickListener() In-App
Respond to in-app message click events. The event contains the following click action metadata:
actionId: A custom identifier you set on the element.urlTarget: An enum specifying how the launch URL for the message will be presented.url: The launch URL for the action, if any.closingMessage: A boolean value indicating if the action resulted in the message being closed.
Live Activity
Applications should allow users to opt-in to Live Activities. For example, your app gives the user the option to start the Live Activity within your US using a button or presenting an IAM. You may start and update a Live Activity via any method without an explicit prompt, unlike Notification Permission or Location Permission. Live Activities appear with the iOS Provisional Authorization UI. Live Activities must be started when your application is in the foreground. We recommend reading Apple’s developer guidelines to learn more about Live Activities.setup()
Allows OneSignal to manage the lifecycle of a LiveActivity on behalf of the application. This includes listening for both pushToStart token updates and pushToUpdate token updates.
setupDefault()
Allows cross platform SDK’s to manage the lifecycle of a LiveActivity by eliminating the need for a customer app to define and manage their own ActivityAttributes. See Cross-platform setup for further details.
enter()
Entering a Live Activity associates an activityId with a Live Activity Temporary Push Token on our server. Specify this identifier when using the Update Live Activities REST API to update one or multiple Live Activities simultaneously.
exit()
Exiting a Live activity deletes the association between an Activity Identifier with the Live Activity push token on our server.
setPushToStartToken()
Optional “low-level” approach to push to start live activities. Offers fine-grained control over the LiveActivity start and update tokens without altering the ActivityAttribute structure. Additional details available here