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.

/wp-content/uploads/2015/07/push5_743133.png

  • Choose Windows Store.

/wp-content/uploads/2015/07/push6_740980.png

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

/wp-content/uploads/2015/07/push7_741101.png

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

/wp-content/uploads/2015/07/push8_741102.png/wp-content/uploads/2015/07/push9_741103.png

  • Click on Services to enable push notification.

/wp-content/uploads/2015/07/push10_741104.png

  • Click on the link ‘Live Services Site’.

/wp-content/uploads/2015/07/push11_741105.png

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

/wp-content/uploads/2015/07/push12_741106.png


  • 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.

/wp-content/uploads/2015/07/push13_741107.png


  • 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.

/wp-content/uploads/2015/07/add_auth_provider_741835.jpg


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.

/wp-content/uploads/2015/07/push14_741108.png

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

/wp-content/uploads/2015/07/push15_741109.png

  • Click Associate to associate your app with the Store.

/wp-content/uploads/2015/07/push16_741110.png

Running and testing the app


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

/wp-content/uploads/2015/07/push1_742006.png


  • Click on Register for Push.

/wp-content/uploads/2015/07/push2_742022.png


  • Click on Allow.

/wp-content/uploads/2015/07/push3_742023.png


  • 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 .

/wp-content/uploads/2015/07/push4_742025.png


  • 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:

Screen Shot 2015-06-01 at 9.56.41 AM.png

  • This is the result at you Kapsel app:

/wp-content/uploads/2015/07/push5_743133.png



  • 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.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Pavan Hampi

    Hello,

    If possible,please share updated link to get index.html as mentioned above in post , because mentioned link is not working as SAP community migrated to new version.

    Thanks in advance.

    Regards,

    Pavan

    (0) 

Leave a Reply