Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »


3.4.0 • Public • Published

IBM Cloud Mobile Services - Cordova Plugin Push SDK

Build Status npm npm

npm package

Cordova Plugin for the IBM Cloud Mobile Services Push SDK


Installing necessary libraries

You should already have Node.js/npm and the Cordova package installed. If you don't, you can download and install Node from

The Cordova library is also required to use this plugin. You can find instructions to install Cordova and set up your Cordova app at

Installing the Cordova Plugin for IBM Cloud Mobile Services Push SDK

Creating a Cordova application

  1. Run the following commands to create a new Cordova application. Alternatively you can use an existing application as well.

    cordova create {your_app_name}
    cd {your_app_name}
  2. Edit config.xml file and set the desired application name in the <name> element instead of a default HelloCordova.

  3. Continue editing config.xml. Update the <platform name="ios"> element with a deployment target declaration as shown in the code snippet below.

    <platform name="ios">
        <preference name="deployment-target" value="8.0" />
        <!-- add deployment target declaration -->
  4. Continue editing config.xml. Update the <platform name="android"> element with a minimum and target SDK versions as shown in the code snippet below.

    <platform name="android">
        <preference name="android-minSdkVersion" value="15" />
        <preference name="android-targetSdkVersion" value="26" />
        <!-- add minimum and target Android API level declaration -->

    The minSdkVersion should be above 15.

    The targetSdkVersion should always reflect the latest Android SDK available from Google.

Adding Cordova platforms

Run the following commands according to which platform you want to add to your Cordova application

cordova platform add ios
cordova platform add android

IMPORTANT: Make sure you use this iOS version for the cordova platform. It is required for the cordova app to build.

Adding the Cordova plugin

From your Cordova application root directory, enter the following command to install the Cordova Push plugin.

cordova plugin add bms-push

This also installs the Cordova Core plug-in, which initializes your connection to IBM Cloud.

From your app root folder, verify that the Cordova Core and Push plugin were installed successfully, using the following command.

cordova plugin list

Note: Existing 3rd party push notification plugins (e.g., phonegap) may interfere with bms-push. Be sure to remove these plugins to ensure proper funcitonality.


Configuring Your iOS Development Environment

  1. Follow the Configuring Your iOS Development Environment instructions from IBM Cloud Mobile Services Core SDK plugin

Updating your client application to use the Push SDK

  1. Enable the push notification and background capabilities .
  2. Add signing certificates

Configuring Your Android Development Environment

Download your Firebase google-services.json for android, and place them in the root folder of your cordova project: [your-app-name]/platforms/android

1.) Prepare and build your cordova Android project

cordova prepare android
cordova build android

2.) Run your Cordova android project either opening in android studion or using cordova CLI

cordova run android

For Android Studion 3.+ users, update the build.gradle file with the folowing -

Change the,

debugCompile project(path: 'CordovaLib', configuration: 'debug') 
releaseCompile project(path: 'CordovaLib', configuration: 'release')


compile project(':CordovaLib')


The following BMSPush Javascript functions are available:

Javascript Function Description
initialize(pushAppGUID, clientSecret,category) Initialize the Push SDK.
registerDevice(options, success, failure) Registers the device with the Push Notifications Service.
unregisterDevice(success, failure) Unregisters the device from the Push Notifications Service
retrieveSubscriptions(success, failure) Retrieves the tags device is currently subscribed to
retrieveAvailableTags(success, failure) Retrieves all the tags available in a push notification service instance.
subscribe(tag, success, failure) Subscribes to a particular tag.
unsubscribe(tag, success, failure) Unsubscribes from a particular tag.
registerNotificationsCallback(callback) Registers a callback for when a notification arrives on the device.

Android (Native) The following native Android function is available.

Android function Description
CDVBMSPush. setIgnoreIncomingNotifications(boolean ignore) By default, push notifications plugin handles all incoming Push Notification by tunnelling them to JavaScript callback. Use this method to override the plugin's default behavior in case you want to manually handle incoming push notifications in native code.


Using BMSPush

Register for Push Notifications

// initialize BMSCore SDK
BMSClient.initialize("Your Push service region");
// initialize BMSPush SDK
var appGUID = "Your Push service appGUID";
var clientSecret = "Your Push service clientSecret";
// Initialize for normal push notifications
var options = {}
// Initialize for iOS actionable push notifications, custom deviceId and varibales for Parameterize Push Notifications 
var options ={"categories":{
BMSPush.initialize(appGUID, clientSecret, options);
var success = function(response) { console.log("Success: " + response); };
var failure = function(response) { console.log("Error: " + response); };
// Register device for push notification without UserId
var options = {};
BMSPush.registerDevice(options, success, failure);
// Register device for push notification with UserId
var options = {"userId": "Your User Id value"};
BMSPush.registerDevice(options, success, failure);

IMPORTANT: Deprecated this way of adding Category in the Initialize method :- var category = {"Category_Name":[{"IdentifierName_1":"actionName_1"},{"IdentifierName_2":"actionName_2"}]} .

You can access the contents of the success response parameter in Javascript using JSON.parse:

var token = JSON.parse(response).token
Available keys

To unregister for push notifications, simply call the following:

BMSPush.unregisterDevice(success, failure);

Retrieving Tags

In the following examples, the function parameter is a success callback that receives an array of tags. The second parameter is a callback function called on error.

To retrieve an array of tags to which the user is currently subscribed, use the following Javascript function:

BMSPush.retrieveSubscriptions(function(tags) {
}, failure);

To retrieve an array of tags that are available to subscribe, use the following Javascript function:

BMSPush.retrieveAvailableTags(function(tags) {
}, failure);

Subscribe and Unsubscribe to/from Tags

var tag = "YourTag";
BMSPush.subscribe(tag, success, failure);
BMSPush.unsubscribe(tag, success, failure);

Receiving a Notification

var handleNotificationCallback = function(notification) {
    // notification is a JSON object

Receiving a Notification Status

 var showNotification = function(notif) {

The following table describes the properties of the notification object:

Handling Notification Actions Click

To identify which action clicked use the following,

var showNotification = function(notif) {
    var identifierName = notif["identifierName"];

Parameterize Push Notifications

To enable the Parameterize IBM Cloud Push Notifications, do the following ,

  1. Add the variables key vaue pair in the BMSPush.initialize options
    var options ={"categories":{
    BMSPush.initialize(appGUID, clientSecret, options);
  2. While sending push notification add the varibale key in {{}}
    "message": {
        "alert": "hello {{username}} , balance on your account {{accountNumber}} is $1200"

Note: If the iOS app is force killed , the Parameterize based notifications may not appear in the device

Property Description
message Push notification message text
payload JSON object containing additional notification payload.
sound The name of a sound file in the app bundle or in the Library/Sounds folder of the app’s data container (iOS only).
badge The number to display as the badge of the app icon. If this property is absent, the badge is not changed. To remove the badge, set the value of this property to 0 (iOS only).
action-loc-key The string is used as a key to get a localized string in the current localization to use for the right button’s title instead of “View” (iOS only).

Example Notification structure:

// iOS
notification = {
    message: "Something has happened",
    payload: {
    sound: "mysound.mp3",
    badge: 7,
    action-loc-key: "Click me"
// Android
notification = {
    message: "Something has happened",
    payload: {
    id: <id>,
    url: <url>

Adding Auto signing in iOS

To set signing credentials iOS create file build.json in your app root. Follow the below patter,

Xcode 8 and iOS 10:

    "ios": {
        "debug": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "FG35JLLMXX4A",
            "packageType": "development",
            "buildFlag": [
                "LD_RUNPATH_SEARCH_PATHS = \"@executable_path/Frameworks\""
        "release": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "FG35JLLMXX4A",
            "packageType": "app-store",
            "buildFlag": [
                "LD_RUNPATH_SEARCH_PATHS = \"@executable_path/Frameworks\""

Earlier versions:

    "ios": {
        "debug": {
            "codeSignIdentity": "iPhone Development",
            "provisioningProfile": "926c2bd6-8de9-4c2f-8407-1016d2d12954",
            "developmentTeam": "FG35JLLMXX4A",
            "packageType": "development"
        "release": {
            "codeSignIdentity": "iPhone Distribution",
            "provisioningProfile": "70f699ad-faf1-4adE-8fea-9d84738fb306",
            "developmentTeam": "FG35JLLMXX4A",
            "packageType": "app-store"

Change teh bundle identifier in config.xml file. After that to build ios use the --buildConfig flag in cordova build command

  cordova build ios --buildConfig

Release Notes

Copyright 2016-17 IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


npm i bms-push

Downloadsweekly downloads





Apache version 2.0




last publish


  • avatar
Report a vulnerability