The push plugin provides an abstraction layer over the
Google Cloud Messaging for Android (GCM)
and
Apple Push Notification Service (APNS).
A notification can be sent to a device registered with an application through a rest call at
Adding and Removing the Push Plugin
The Push plugin is added and removed using the Cordova CLI.
To add the Push plugin to your project, use the following command:
cordova plugin add\push
To remove the Push plugin from your project, use the following command:
cordova plugin rm com.sap.mp.cordova.plugins.push
A notification can be sent to a device registered with an application through a rest call at
http://SMP_3.0_SERVER:8080/Notifications/application_registration_id
Adding and Removing the Push Plugin
The Push plugin is added and removed using the Cordova CLI.
To add the Push plugin to your project, use the following command:
cordova plugin add
To remove the Push plugin from your project, use the following command:
cordova plugin rm com.sap.mp.cordova.plugins.push
Methods
(static) checkForNotification(callback)
This method checks for any notifications received while the application was not running in the foreground. Application developer can call this
function directly or register with an event handler to be called automatically. It is ok to call this function evenif the device is not yet registered for push notification.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback function that receives the notification. The callback function will receive a string as it's argument. This string will contain the notification message send from the server intact. |
Example
function processBackgroudMessage(mesg){
}
function checkBackgroundNotification() {
sap.Push.checkForNotification(processBackgroudMessage);
}
document.addEventListener("onSapLogonSuccess", checkBackgroundNotification, false);
document.addEventListener("onSapResumeSuccess", checkBackgroundNotification, false);
(static) getBadgeNumber(callback)
Used to fetch the badge count for the application. This function is used only by iOS. Other platforms do not have the badge count concept.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Success callback to call when to send the badge count. The callback function will contain an argument in json format with the current badge count. Look into the example for the deail on how to use them. |
Example
function getBadgeNumCallback(data) { badgecount = data;}
sap.Push.getBadgeNumber(getBadgeNumCallback);
(static) initPush(the)
This method is used to initialize the push notifiation in the javascript
Parameters:
Name | Type | Description |
---|---|---|
the |
function | pushprocesor function wich will be called based on the push event |
Example
var myPushProcessor = function(msg) {
alert(JSON.stringify(msg));
}
document.addEventListener("onSapResumeSuccess", function() {sap.Push.initPush(myPushProcessor);}, false);
document.addEventListener("onSapLogonSuccess", function() {sap.Push.initPush(myPushProcessor);}, false);
(static) registerForNotificationTypes(types, successCallback, errorCallback, notificationlistenerfunc, senderIdopt)
Function called by the application to register notification types to receive.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
types |
string | Types of notifications the application wants to receive. The different types of notifications are expressed in notificationType
Notificaion types allowed are Disable all notifications (NONE: 0), Set badge count on app icon (BADGE: 1), Play sounds on receiving notification (SOUNDS: 2) and Show alert on receiving notification (ALERT: 4). |
|
successCallback |
string | Success callback to call when registration is successful. | |
errorCallback |
string | Error callback to call when registration attempt fails. | |
notificationlistenerfunc |
string | The function that receives the notification for processing by the application. | |
senderId |
string |
<optional> |
The sender ID that is used for GCM registration. For other platforms it is null. |
Example
regid = "211112269206";
function registerSuccess(mesg){}
function registerFailure(mesg) {}
function ProcessNotification(mesg){}
sap.Push.registerForNotificationTypes(sap.Push.notificationType.badge | sap.Push.notificationType.sound | sap.Push.notificationType.alert, registerSuccess, registerFailure, ProcessNotification, regid);
(static) resetBadge(callback)
Used to reset the badge count for the application. This function is used only by iOS. Other platforms do not have the badge count concept.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Success callback to call when the badge count is reset. The callback function will contain an argument in string format. This argument can be used for informative purpose. |
Example
function badgeCallback(mesg){}
sap.Push.resetBadge(badgeCallback);
(static) setBadgeNumber(number, callback)
Used to set the badge count for the application. This function is used only by iOS. Other platforms do not have the badge count concept.
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The badge count to set for the application. |
callback |
function | Success callback to call when to send the badge count. The callback function will contain an argument in string format. This argument can be used for informative purpose. |
Example
function badgeCallback(mesg){}
badgenum = 10;
sap.Push.setBadgeNumber(badgenum, badgeCallback);
(static) unregisterForNotificationTypes(callback)
Function called by the application to unregister from future notifications.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Success callback to call when deregistration is successful. This callback function will contain a string with a message. This message is just for informative purpose. |
Example
function unregCallback(mesg){}
sap.Push.unregisterForNotificationTypes(unregCallback);
(static) updatePushCapability(capabilityNemeopt, capabilityValueopt)
This function is called by the apliation to update push capability value for fiori client
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
capabilityNeme |
string |
<optional> |
The name of the capability. |
capabilityValue |
string |
<optional> |
the value of the capability. |
Example
sap.Push.updatePushCapability('testName', 'testValue');
(static) updatePushCapabilityWithJson(capabilityJsonValueopt)
This function is called by the aplication to update push capability value for fiori client
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
capabilityJsonValue |
object |
<optional> |
The JSON value of capability list. |
Example
sap.Push.updatePushCapabilityWithJson([{"Category": 'categoryName1','CapabilityName':'testName1', 'CapabilityValue':'testValue1'},{"Category": 'categoryName2','CapabilityName':'testName2', 'CapabilityValue':'testValue2'}]);
Type Definitions
callback(devtokopt)
This method updates the application with the new device token in the SAP Mobile Platform server.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
devtok |
string |
<optional> |
The device token received from the APNS/GCM device registration. |
Example
function callback(mesg) {}
devToken ="123123213213";//sample device token
sap.Push.updateWithDeviceToken(devToken, callback);