I. Introduction
Push Notification is one of the unique features of windows phone 7. This feature allows common developers to implement multi-tasking in disguise (although not really multi-tasking ). It establishes a dedicated, persistent, and stable channel between the mobile app and webservice to push notifications. After the channel is established, the mobile app can receive any information about webservice.
Ii. Classification
There are three main Push Notification types:
1. Tile Notification:
Is a way to change the icon content (images, text, etc.) in the Quick Lanuch area. However, you need to pin the program to start before using it.
2. Toast Notification:
Display a prompt bar on the screen. Click the prompt bar to open the application.
3. Raw Notification:
Is to directly use Http to receive (http polling) notifications. And is invisible. notifications will be sent in the future.
For the above notifications, a server needs to send the notifications in push notification mode, that is, to use push notification, a server is required.
3. Create a server
For the server side, different notifications are sent in Http mode. However, when sending notifications, You need to configure the corresponding parameters, to tell the Push Notification Service what type is sent.
HttpWebRequest request = (HttpWebRequest) WebRequest. Create (channelUri );
Request. Method = WebRequestMethods. Http. Post;
Request. ContentType = "text/xml; charsets = UTF-8 ";
Request. ContentLength = icationicationmessage. Length;
Request. Headers ["X-MessageID"] = Guid. NewGuid (). ToString ();
1. Toast notification:
Request. Headers ["X-WindowsPhone-Target"] = "toast ";
Request. Headers [X-icationicationclass]
Message:
"Content-Type: text/xml \ r \ nX-WindowsPhone-Target: token \ r \ n"
<? Xml version = "1.0" encoding = "UTF-8"?>
<Wp: Notification xmlns: wp = "WPNotification">
<Wp: Tile>
<Wp: BackgroundImage>
<Background image path>
</Wp: BackgroundImage>
<Wp: Count>
<Count>
</Wp: Count>
<Wp: Title>
<Title>
</Wp: Title>
</Wp: Tile>
</Wp: Notification>
2. Token notification:
Request. Headers ["X-WindowsPhone-Target"] = "token ";
Request. Headers [X-icationicationclass]
Message:
"Content-Type: text/xml \ r \ nX-WindowsPhone-Target: toast \ r \ n"
<? Xml version = "1.0" encoding = "UTF-8"?>
<Wp: Notification xmlns: wp = "WPNotification">
<Wp: Toast>
<Wp: Text1>
<String>
</Wp: Text1>
<Wp: Text2>
<String>
</Wp: Text2>
</Wp: Toast>
</Wp: Notification>
3. raw notification
Request. Headers [X-icationicationclass]
Request. BeginGetRequestStream ();
Stream requestStream = request. EndGetRequestStream ();
RequestStream. BeginWrite (message );
Response Data
Response. StatusCode // OK indicates the operation is successful. Otherwise, you can check the corresponding error code table and check the table to get the current status.
Response. Headers [X-MessageID]
Response. Headers [X-DeviceConnectionStatus]
Response. Headers [X-SubscriptionStatus]
Response. Headers [X-icationicationstatus]
4. Create a client
Httpicationicationchannel httpChannel = HttpNotificationChannel. Find (ChannelName );
HttpChannel. Open ();
// Bind notification
HttpChannel. BindToShellToast ();
HttpChannel. BindToShellTile (uris );
// Obtain the notification channel URI
HttpChannel. ChannelUriUpdated + = new EventHandler <icationicationchannelurieventargs> (httpChannel_ChannelUriUpdated );
// Obtain Raw notification
HttpChannel. httpicationicationreceived + = new EventHandler
// Get Toast notification
HttpChannel. ShellToastNotificationReceived + = new EventHandler <icationeventeventargs> (httpChannel_ShellToastNotificationReceived );
// Get Push notification error message
HttpChannel. erroccurred + = new EventHandler <icationicationchannelerroreventargs> (httpChannel_ExceptionOccurred );
Tile notification is received by the system, so there is no corresponding Event.
The above are some basic steps for pushing notification. Specific instances are available in WP7TrainningKit.