OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

SMS SDK Methods

Collect SMS Numbers through your app or website.

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 vs Push Records

SMS and Push subscribers will have separate OneSignal Player IDs (user records). This is to manage the case where a user opts-out of one you can still send messages to the other.

🚧

Note on Network Latency

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.

OneSignal.push(function() {
  OneSignal.setSMSNumber("+11234567890");
});
OneSignal.setSMSNumber("+11234567890");
OneSignal.setSMSNumber("+11234567890")
OneSignal.setSMSNumber("+11234567890")
[OneSignal setSMSNumber:@"+11234567890"];
OneSignal.setSMSNumber("+11234567890");
OneSignal.shared.setSMSNumber(smsNumber: "+11234567890")
// Ionic 5 Capacitor may need to use (window as any).plugins.OneSignal
window.plugins.OneSignal.setSMSNumber("+11234567890");

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.

Logout Number

logoutSMSNumber Method

If your app or website implements logout functionality, you can call logoutSMSNumber to dissociate the SMS from the device:

OneSignal.push(function() {
  OneSignal.logoutSMS();
});
OneSignal.logoutSMSNumber();
OneSignal.logoutSMSNumber()
[OneSignal logoutSMSNumber];
OneSignal.logoutSMSNumber();
OneSignal.shared.logoutSMSNumber()
// Ionic 5 Capacitor may need to use (window as any).plugins.OneSignal
window.plugins.OneSignal.logoutSMSNumber();

SMS Subscription Observer

addSMSSubscriptionObserver Method

Mobile App only - 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:

OneSignal.addSMSSubscriptionObserver(stateChanges -> {
    // Work with state changes          
  });
[OneSignal addSMSSubscriptionObserver:self];
OneSignal.add(self as OSSMSSubscriptionObserver)
OneSignal.addSMSSubscriptionObserver((event) => {
  console.log("OneSignal: sms subscription changed: ", event);
});
OneSignal.shared.setSMSSubscriptionObserver((OSSMSSubscriptionStateChanges changes) {
});

Now, whenever the sms subscription changes, this method will be called:

OSSMSSubscriptionObserver subscriptionObserver = new OSSMSSubscriptionObserver() {
   @Override
   public void  public void onSMSSubscriptionChanged(OSSMSSubscriptionStateChanges stateChanges) {
   }
};
-(void)onOSSMSSubscriptionChanged:(OSSMSSubscriptionStateChanges *)stateChanges {
    
}
func onOSSMSSubscriptionChanged(_ stateChanges: OSSMSSubscriptionStateChanges!) { 
    
}

getSMSId Method

Web only - Get the OneSignal Player ID associated with the SMS Phone Number Record.

OneSignal.push(function() {
  OneSignal.getSMSId();
});

Updated 2 months ago



SMS SDK Methods


Collect SMS Numbers through your app or website.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.