How to send and receive push notifications for Windows Phone 8 – Introduction

You can setup your apps to receive push notifications from a web-service and update its live tile, display a toast notification or a raw notification. Firstly your app needs to be registered for receiving push notifications and then a web service (or even an app capable of sending messages to Microsoft Push Notification Service). MSDN describes its push notification service as

“The Microsoft Push Notification Service in Windows Phone is an asynchronous, best-effort service that offers third-party developers a channel to send data to a Windows Phone app from a cloud service in a power-efficient manner.”

The diagram (taken from MSDN) shows how a push notification is sent.

  1. Your app requests a push notification URI from the Push client service.
  2. The Push client service negotiates with the Microsoft Push Notification Service (MPNS), and MPNS returns a notification URI to the Push client service.
  3. The Push client service returns the notification URI to your app.
  4. Your app can then send the notification URI to your cloud service.
  5. When your cloud service has info to send to your app, it uses the notification URI to send a push notification to MPNS.
  6. MPNS routes the push notification to your app.

 

Note: It is recommended that your web-service should be authenticated and use a secure channel. Heres how you could set up an authenticated web-service. Later on we will show how to create a web-service using PHP but not ASP.NET.

To send push notifications your app/ web-service should do the following

  • For each Windows Phone device a POST message should be created
  • There are different formats for toast, tile and raw notifications. Construct a message accordingly (which will be describe later in the post). Downgrade your message for windows phone 7 by removing fields that are not supported
  • Post the messages to push notification service
  • Get the response from MPNS and respond accordingly

You can have 3 different types of notifications in your app

Toast

A toast notification displays for about 10 seconds unless the user dismisses it with a flick to the right. If the user taps the toast, by default, your app’s start screen launches.

Tile

A Tile is an image that represents your app on the Start screen. Windows Phone 8 supports three Tile templates: flip, iconic, and cycle.

Raw notifications

They are notifications that appear while the app is running.

Custom HTTP Headers

Custom HTTP headers can include a notification message ID, batching interval, the type of push notification being sent, and the notification channel URI.

  • The MessageID is the notification message ID associated with the response. If this header is not added to the POST request, the push notification service omits this header in the response.

For example: XMessageIDUUID

  • The NotificationClass is the batching interval that indicates when the push notification will be sent to the app from the push notification service. 

For example: X-NotificationClass: 1

  • The Notification Type is the type of push notification being sent. Possible options are Tile, toast, and raw. If this header is not present, the push notification will be treated as a raw notification.

For example: X-WindowsPhone-Target:toast 

Push notifications batching intervals

The batching interval describes the values different types of notifications could take for various types of delivery times.

Time/Type Toast Tile Raw
Immediate delivery 2 1 3
Delivery within 450 seconds 12 11 13
Delivery within 900 seconds 22 21 23

 

Special characters

The following characters should be encoded while using in XML

In the next few posts I will explain how to integrate tile, toast or raw notifications in your windows phone app.