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.
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.
Setting the User’s SMS Number
setSMSNumber
Method
The setSMSNumber
method allows you to set the user’s SMS number with the OneSignal SDK. We offer several overloaded versions of this method.
Logout Number
logoutSMSNumber
Method
If your app or website implements logout functionality, you can call logoutSMSNumber
to dissociate the SMS from the device:
Listening for subscription changes
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” |