Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
DanielSilva1
Advisor
Advisor

If you have already read my article [Kapsel] How to use the Push plugin on iOS, the first part of this article will be repetitive, however it is necessary to introduce the push notification subject.

Introduction


As very well described by Dan van Leeuwen at Getting Started with Kapsel - Part 4 -- Push, "push messages provide a way to inform or remind a user that an action should be taken by delivering a short message that appears as a notification on the device.  When clicked on, the app that is associated with the message is opened.  The Kapsel push plugin provides an abstraction layer over the Google Cloud Messaging for Android (GCM), Windows Push Notification Services (WNS) and Apple Push Notification Service (APNS)A notification can be sent to a device registered with an application via a REST call to http://SMP_3.0_SERVER:8080/Notifications/application_registration_id".


There are three agents working on the push notification feature:

  1. The SAP Mobile Platform Server. It is responsible for gathering push notifications and device IDs from the client using the notification service provider.
  2. The Kapsel app running on the device, which is responsible for receiving the notifications.
  3. The notification service provider (APNS, GCM or WNS).


This plugin allows users or developers to register the developed app for receiving push notifications. It is also possible to process notification in the background. The Push API offers tasks to:

  • Register or unregister for push notifications.
  • Handle push notifications.
  • Configure push notifications.
  • Handle error messages.

Proxy settings should be set in the Administration and Monitoring tool, under Settings > System > HTTP Proxy Settings in case you are using an SMP Server in a network that uses a proxy in order to have your SMP Server accessing GCM, APNS and WNS servers. Do not forget to remove these settings if the network, where your SMP Server is, is not using a proxy.


As recommended by Dan, "for additional details see the JavaScript file in a project that includes this plugin at project_name\www\plugins\com.sap.mp.cordova.plugins.push\www\push.js or the JS Documentation at Kapsel Push API Reference."


This document is focused on Kapsel push plugin used on Windows (WNS). So, if you wish to have an example and a good document about how to use the Kapsel push plugin on Android (GCM), I strongly recommend Dan's document: Getting Started with Kapsel - Part 4 -- Push. For iOS, I recommend my article [Kapsel] How to use the Push plugin on iOS.


Understanding Windows Push Notification Services (WNS)

As described in Microsoft's webpage Windows Push Notification Services (WNS) overview (Windows Runtime apps)"The Windows Push Notification Services (WNS) enables third-party developers to send toast, tile, badge, and raw updates from their own cloud service. This provides a mechanism to deliver new updates to your users in a power-efficient and dependable way."


I am not going to describe everything about it, because my colleague Milton Chandradas already did that very well in his article New features for Windows in SAP Mobile Platform SDK - Part 2 (Push notification) section "How it works?". So I strongly recommend you read it to understand better how it works.


Let's do it!


Below you will understand how to configure SAP Mobile Platform for push notification on Windows and how to associate your Kapsel app to the store. Both steps are mandatory and were written by my colleague Milton Chandradas in the appendix of his article New features for Windows in SAP Mobile Platform SDK - Part 2 (Push notification). I copied it here for simplicity, but I recommend again that you visit his page.

Configuring SAP Mobile Platform for push notification

  • Browse to http://dev.windows.com
  • Log in with your Windows developer account. If you and your company do not have one, you will need to pay for one.
  • Click on ‘Submit apps’ icon.

  • Choose Windows Store.

  • From the dashboard menu in the left pane, click on the option ‘Submit an app’.

  • Give the app an unique name, because it will be used to bring the notifications.

  • Click on Services to enable push notification.

  • Click on the link 'Live Services Site'.

  • Make note of Package SID and client secret.  You will enter these values in the SAP Mobile Platform application configuration.


  • Go through Dan's instructions at Configuring a Kapsel App in the Management Cockpit to create an app in the Administration and Monitoring tool using the app ID com.mycompany.push.
    • Set any URL as your OData endpoint, since we are not going to consume data at this sample app.
    • Use Basic SSO mechanism and the Default security provider.


  • Go to the Push tab. Under Windows, enter the Package SID and Client Secret that you have made not two steps behind. Then, save the configuration.


  • Now you need to add a System Login (Admin Only) authentication provider to the Notification security provider.
    • Go to Settings > Security Profiles.
    • Click on Notification.
    • Click on the Add button.
    • Set Authentication Provider as System Login (Admin Only).
    • Set the Username field as smpPushUser, the Password field as smpPushPwd and the Roles field as Notification User.
    • Click on Save > Save.
    • Restart your SMP Server.
    • This user and password will be used later to send a push notification to your device.


Creating the app


  • Create your Cordova project and add the Windows platform to it.
    • Open a Terminal.
    • If you do not have one, create a Kapsel_projects folder inside your Development folder.
    • Run the following commands in yout terminal shell:
      • cordova -d create <DEVELOPMENT_PATH>/Kapsel_Projects/PushDemo com.sap.demo.push PushDemo
      • cd <DEVELOPMENT_PATH>/Kapsel_Projects/PushDemo
      • cordova -d platform add windows8

  • Add the push plugin to your Cordova project, running the following command in your terminal shell:
    • cordova -d plugin add com.sap.mp.cordova.plugins.push --searchpath <SMP_SDK_PATH>/KapselSDK/plugins/

  • In your Cordova project, replace the www/index.html by the content of the following compressed file: index.html.zip
    • In line 12 of the copied index.html file, set serverHost as you SMP Server's hostname or IP address.

  • Copy your www files to the iOS platform folder, running the following command in your terminal shell:
    • cordova -d prepare windows8


  • Go to <DEVELOPMENT_PATH>/Kapsel_Projects/PushDemo/platforms/windows, and open the CordovaApp.sln with Visual Studio.


  • Under CordovaApp.Windows (Windows 8.1), open the package.windows.appxmanifest file and make the following changes:
    • Under Application tab, Notifications, set Lock screen notifications as Badge and Tile Text.
    • Under Visual Assets tab, select Badge Logo. Choose one of the scales, click on the ... button and select a logo. Then save your project.

Associating app with the Store

  • From within Visual Studio, right click on the CordovaApp.Windows (Windows 8.1) project and select Store -> Associate App with the Store.

  • Login to your Windows developer account if prompted.
  • Select your app name and click Next.

  • Click Associate to associate your app with the Store.

Running and testing the app


  • Click on the CordovaApp.Windows (Windows 8.1) project and on Play button.


  • Click on Register for Push.


  • Click on Allow.


  • Dan warns us that "when reopening the app, the Register For Push button must be pressed again or in a non-sample app, it should be called in the logonSuccessCallback method which would be called each time the application starts".


  • The next step is to test your app. For this, you will need to send a REST request to your Kapsel app via SMP Server. So, open SMP cockpit and go to Applications > Registrations. In the Registrations table, you will find the Registration ID of your app. Take note of that ID .


  • The URL you should use to send the REST request is: http://<SMP_SERVER>:8080/restnotification/registration/<REGISTRATION_ID>. The following payload: {"alert":"<ALERT_TITLe>", "data":"<ALERT_DATA>" }. Set also the Content-Type to application/json.


  • When prompted for a User Name and Password enter smpPushUser and smpPushPwd.


  • Using the Advanced Rest Client chrome app, this is the result you should have:

  • This is the result at you Kapsel app:



  • You can also send push notification to all devices registered for a specific app or to all the devices of a specific user. Please find more details here Notification Data Sent Using Push API.


  • Dan van Leeuwen also talks about some error codes you may have when you are sending a REST request to your app:


"If the status is 403, this indicates a permission problem.  Double check that that the correct user id and password for the Notification security profile were correctly entered.  Also double check that the correct role name of Notification User was assigned to the Roles of the authentication provider for the Notification security profile.


If the status is 404, this may indicate that the app did not successfully register for notifications.  Try pressing the Register for Push button again and verify that the Successfully registered alert displays."

1 Comment