Handling SMS Notifications in iOS

improve this page | report issue

Overview

SMS notifications are a sub-set of Push Notification, as such make sure to first go through the Push notifications in iOS tutorials.

Prerequisites:

Jump to:

Notifications API

In SMS notifications, when registering the device, a phone number value is passed.

Challenge Handlers

If the push.mobileclient scope is mapped to a security check, you need to make sure matching challenge handlers exist and are registered before using any of the Push APIs.

Initialization

Required for the client application to connect to MFPPush service with the right application context.

  • The API method should be called first before using any other MFPPush APIs.
  • Registers the callback function to handle received push notifications.
MFPPush.sharedInstance().initialize()

Register Device

Register the device to the push notifications service.

MFPPush.sharedInstance().registerDevice(jsonOptions){ (response, error) -> Void in
     if error == nil {
         // Successfully registered
     } else {
         // Registration failed with error
     }
 })
  • optionObject: an jsonOptions containing the phone number to register the device with. For example:
let phoneNumber: String = self.phoneNumberTF.text!

let jsonOptions: [AnyHashable: Any] = [
    "phoneNumber": phoneNumber
]

if JSONSerialization.isValidJSONObject(jsonOptions) {
    // JSON is valid and can be sent with registerDevice request
}

You can also register a device using the Push Device Registration (POST) REST API

Unregister Device

Unregister the device from push notification service instance.

MFPPush.sharedInstance().unregisterDevice { (response, error)  -> Void in
    if error == nil {
        // Unregistered successfully
    } else {
        // Failed to unregister
    }
})

Using an SMS subscribe servlet

REST APIs are used to send notifications to the registered devices. All forms of notifications can be sent: tag & broadcast notifications, and authenticated notifications

To send a notification, a request is made using POST to the REST endpoint: imfpush/v1/apps/<application-identifier>/messages.
Example URL:

https://myserver.com:443/imfpush/v1/apps/com.sample.sms/messages

To review all Push Notifications REST APIs, see the REST API runtime services topic in the user documentation.

To send a notification, see the sending notifications tutorial.

Image of the sample application

Sample application

Click to download the Xcode project.

Sample usage

Follow the sample’s README.md file for instructions.

Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on December 01, 2017