The methods below require the OneSignal SDK versions 3 & 4.It is recommended to upgrade to our latest version 5 SDKs for User Model APIs.See Update to User Model for migration steps.
If you have not done so, we always recommend updating the OneSignal SDK to the latest version to get access to the latest features:
SMS and Push subscribers will have separate OneSignal Subscription IDs (user records). This is to manage the case where a user opts-out of one you can still send messages to the other.
If there are networking issues, functions may take 30+ seconds to return. In the code examples below we provide callbacks to track when these return.Make sure to keep functions from blocking the user interface, otherwise your app may appear unresponsive to the user.
If you have a backend server, we strongly recommend using Identity Verification with your users. Your backend can generate an SMS authentication token and send it to your app or website.Note that the SMS number is required to be in the E.164 format. Please see our SMS Troubleshooting guide for more details.
The SMS Subscription Observer tracks changes to SMS subscriptions (ie. the user sets their SMS number or logs out). In order to subscribe to SMS subscription changes you can implement the following:
Event Object Property
Type
sms
string e.g: “+12149874829”
Copy
Ask AI
OneSignal.addSMSSubscriptionObserver(stateChanges -> { // Work with state changes });
Now, whenever the sms subscription changes, this method will be called:
Copy
Ask AI
OSSMSSubscriptionObserver subscriptionObserver = new OSSMSSubscriptionObserver() { @Override public void public void onSMSSubscriptionChanged(OSSMSSubscriptionStateChanges stateChanges) { }};