Handling SMS Notifications in Cordova

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 Cordova tutorials.
SMS notifications in Cordova applications are supported for iOS and Android.

Prerequisites:

Jump to:

Notifications API

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

Register Device

Register the device to the push notifications service.

MFPPush.registerNotificationsCallback(notificationReceived);

function registerDevice() {
    var phoneNumber = prompt("Enter Your 10 digit phone number");
    if(phoneNumber != null && phoneNumber!="" && /^\d+$/.test(phoneNumber)) {
        var options = {};
        options.phoneNumber = phoneNumber;
        MFPPush.registerDevice(options, 
        function(successResponse) {
            alert("Successfully registered");
            enableButtons();
        }, function(failureResponse) {
            alert("Failed to register");
        });
        return true;
    }

    else {
        alert("Failed to register, You have entered invalid number");
    }
}

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

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 Cordova project.

Note: The latest version of Google Play Services is required to be installed on any Android device for the sample to run.

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 January 10, 2017