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

/wp-content/uploads/2015/04/push1_696298.png

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.

/wp-content/uploads/2015/04/push2_696302.png

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.

/wp-content/uploads/2015/04/push3_696303.png

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.

/wp-content/uploads/2015/04/push4_696304.png

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

Appendix

Configuring SAP Mobile Platform for push notification

  • Browse to  http://dev.windows.com
  • Log in with your Windows developer account
  • Click on ‘Submit apps’ icon

/wp-content/uploads/2015/04/push5_696314.png

  • Choose Windows Store

/wp-content/uploads/2015/04/push6_696315.png

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

/wp-content/uploads/2015/04/push7_696316.png

  • Give the app an unique name

/wp-content/uploads/2015/04/push8_696317.png

/wp-content/uploads/2015/04/push9_696318.png

  • Click on Services to enable push notification

/wp-content/uploads/2015/04/push10_696319.png

  • Click on the link ‘Live Services Site’

/wp-content/uploads/2015/04/push11_696320.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/04/push12_696321.png

/wp-content/uploads/2015/04/push13_696322.png

Associating app with the Store

  • From within Visual Studio, right click on the project and select Store -> Associate App with the Store

/wp-content/uploads/2015/04/push14_696323.png

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

/wp-content/uploads/2015/04/push15_696324.png

  • Click Associate to associate your app with the Store

/wp-content/uploads/2015/04/push16_696325.png

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply