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: 
miltonc
Product and Topic Expert
Product and Topic Expert
0 Kudos

Note:  The code for the sample application is now published.

In this blog, I will be talking about how you can enable push notification on Windows Store applications built using the SAP Mobile Platform SDK (hereinafter referred to as “SMP SDK” or “SDK”).  Push notifications are ubiquitous in the mobile world.  Users are accustomed to getting the latest information immediately on their mobile device.  The SAP Mobile Platform runtime (hereinafter referred to as “SMP Server”) uses Windows Push Notification Services (hereinafter referred to as “WNS”) to send toast, tile, badge and raw updates to the mobile application in a dependable manner.


How it works?

There are basically 4 players in the push notification process.

  1. Windows Store application – This is the application that the end user interacts with
  2. Notification Client Platform (NCP) – Part of the Windows 8.1 OS.  It interacts with WNS and passes notifications to the client application
  3. Windows Notification Service (WNS) – Responsible for sending notifications to devices
  4. Cloud Service – SAP Mobile Platform performs this role – responsible for creating the push notification

The workflow involves 6 steps.

  1. Client application requests Channel URI from the Notification Client Platform
  2. Notification Client Platform talks with WNS to obtain Channel URI
  3. Notification Client Platform returns Channel URI to client application
  4. Client application sends Channel URI to SAP Mobile Platform
  5. Something changes in the backend database.  SAP Mobile Platform sends the notification to WNS and Channel URI to WNS
  6. WNS sends the notification to Notification Client Platform which handles tile or toast updates



Step by step instructions on Push Notification workflow

As mentioned earlier, the Push Notification workflow has 6 important steps.  Let’s look at each step one by one.

Step 1

Client application requests Channel URI from Notification Client Platform


The Channel URI can be requested asynchronously from the Notification Client Platform by calling the CreatePushNotificationChannelForApplicationAsync method.  This can be done immediately after the on-boarding process.  It is recommended to make this call in the LogonCompleted event handler method.

// Request a push notification channel.

var CurrentChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

Note:  The Channel URI can expire in 30 days.  So periodically renew the Channel URI as push notifications to expired Channel URI’s will be dropped. In the sample application, we request the Channel URI every time user logs in successfully and persist it in local storage.  If the newly requested Channel URI is different from the Channel URI in local storage, then we know that the Channel URI has changed.  We then send this changed Channel URI to the SMP Server.

Step 2

Notification Client Platform talks with WNS to obtain Channel URI


The Windows 8.1 operating system must be able to reach the WNS.  In the Package.appxmanifest file, make sure that the application has Internet capabilities.  This is enabled by default.

Step 3

Notification Client Platform returns Channel URI to client application


No further action required from the developer.

Step 4

Client application sends Channel URI to SAP Mobile Platform


The client application must submit an HTTP POST request to the SAP Mobile Platform and send the newly acquired Channel URI as part of the message body.

URL: http://{SMPHost:Port}/odata/applications/{latest|v1/}{appid}/Connections('{appcid}')

Method : PUT

HTTP Headers :

  "Content-Type" = "application/atom+xml"

  "X-HTTP-METHOD" = "MERGE"

Body :

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

  <content type="application/xml">

    <m:properties>

<d:WnsChannelURI>{WNS Channel URI}</d:WnsChannelURI>

    </m:properties>

  </content>

</entry>

This can be accomplished asynchronously by

var writableSettings = logonCore.ApplicationSettings.GetWritableSettings();

writableSettings["WnsChannelURI"].Value = "YOUR_CHANNEL_URI_HERE_AS_A_STRING";

await logonCore.ApplicationSettings.UpdateSettingsAsync(writableSettings);

Step 5

SAP Mobile Platform sends notification and Channel URI to WNS


SAP Mobile Platform takes care of sending the notification and Channel URI to WNS behind the scenes as long as it’s properly configured.  However, the developer can trigger this action by sending an HTTP POST message. This is typically done when some value changes in the backend database and the end user needs to be notified of the change.

URL: http://{SMPHost:Port}/restnotification/registration/{applicationRegistrationId}

Method : POST

Body :

{"alert":"New Approval Request has been submitted"}

See appendix on how to configure the SAP Mobile Platform for Windows Push Notification.

Step 6

WNS sends notification to Notification Client Platform which handles toast and tile updates


The client application must be configured to receive toast notifications.  Also, for tile updates the client application must be pinned to the Start screen using the Medium tile size.

See you all in the next blog where I will be talking about batch processing.

Appendix

Configuring SAP Mobile Platform for push notification

  • Choose Windows Store

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

  • Give the app an unique name

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

Associating app with the Store

  • From within Visual Studio, right click on the 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