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.
There are basically 4 players in the push notification process.
The workflow involves 6 steps.
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.
Configuring SAP Mobile Platform for push notification
Associating app with the Store
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
14 | |
13 | |
13 | |
12 | |
8 | |
8 | |
7 | |
5 | |
5 |