Handling SMS Notifications in iOS
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:
- Make sure you have read the following tutorials:
- PMF to run locally, or a remotely running PMF.
- PMF CLI installed on the developer workstation
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.
Sample application
Click to download the Xcode project.
Sample usage
Follow the sample’s README.md file for instructions.
▲