Introduction
The
Windows Push Notification Service is used to enable a developer to send toast,
tile and badge. WNS provides a mechanism to deliver new updates to the user.
Before
we learn Windows Push Notification I would like to describe
the Package.appmanifest file and its settings. This file is automatically created
when you create a new Metro style project. This is an XML file that can contain
the project configuration settings. Let's have a quick look at all these settings
which are in the Package.appmanifest file.
This file allows us
to set four kinds of settings (Application UI, Capabilities, Declarations,
Packaging) as you can see in the below image. Application UI and Packaging
settings are important in order to do Windows Push Notification.
[Remember]: In the above
image all settings are OK but Toast
capable settings are (not set), it
means our application cannot send Toast. In order to allow our application to
send Toast, we need to set yes in place of (Not Set). The image below shows the packaging settings.
Packaging settings
allow us to set our live SDK setting, look at the Package name, it
is a place where we need to add our package name and we can get this package
name after we register our application on Windows Live Dashboard. Please click Register
application on live dashboard to know how to
register application on Live dashboard.
Now
we move back on the Push notification. Let us see how the WNS server works in order
to send Toast, Tile and badge.
The
above image showing 6 steps, let we see all these steps one by one.
- Metro style application uses WinRT APIs to open a
new Channel URI to server, so our application sent a request to Notification
Client Platform.
- Notification Client makes a request to WNS server
and get channel URI as response.
- Notification Client give this Channel URI to our
metro style application
Any 3rd party
application need to obtain its client ID (SID) and client secret in order to
communicate with cloud service. In order to get application client ID (SID) and
client secret we need to register our application on live Dashboard (This
article is push notification vie using live SDK). Please click Register
application on live Dashboard to know how to
register application on live dashboard.
- Metro style application send request to the Cloud
server to get Authentication token.
[Remember] we need to use
Channel URI, Client Secret and Client ID (SID) in order to get access token
from cloud service.
OAuthToken
class is
just have 2 property (Access Token and Token Type), It has sated by OnAuthenticate()
method.
- Cloud Service creates a request to the WNS Server
by using Channel URI and Authentication Token. If everything is going very
smooth then WNS return status 200 as
its response
[Remember]:PushWNS()
method using Notification type and Notification
XML. Please look at the below table to get idea of Notification Type and
Notification XML.
Notification
Name
| Notification
Type
| Notification
XML
|
Badge
| "wns/badge"
| "<?xml
version='1.0' encoding='utf-8'?><badge value=\"2\"/>"
|
Tile
| "wns/tile"
| "<tile><visual
version=\"1\"><binding
template=\"TileWideText03\"> <text
id=\"1\">Hello World! My tile
notification</text></binding><binding
template=\"TileSquareText04\"><text
id=\"1\">Hello
World!</text></binding></visual></tile>"
|
Toast
| "wns/toast"
| "<?xml
version='1.0' encoding='utf-8'?><toast><visual
version='1'><binding template='ToastText01'><text id='1'>My
first Toast</text></binding></visual></toast>"
|
- Notification Client can get this response and
send it to our application.
When
I was starting learning this I was confused how to verify these Badge, Tile and
toast are pushed or not, so let me tell you how to verify it
- Badge: Once you send badge successfully, please
go to win8 Dashboard and check your application. Look at the below image
- Tile: Once you send Tile successfully, please go
to win8 Dashboard and check your application. Look at the below image
- Toast: Once you send Toast successfully, just
wait 2-3 second you will get a popup message. Look at the below image
I hope This article will help you to send
push notification by using metro style application.