Windows Phone 8 開發快速入門(八)



主要內容:推送通知

推送通知

推送通知爲開發者提供了定期將信息傳遞給應用的功能,即使應用沒有啓動。圖塊可以爲用戶顯示最關注的信息

推送通知數據流

Notifications service<--->MPNS(Microsoft hosted server)

Third-party service<-->Notificatins service

Third-party service4-->MPNS

服務器端發起的通信

推送通知的架構

三種類型的推送通知:Raw,Toastand Tile

Raw:通知消息的內容由程序定義,如果程序運行,則直接發送給應用

使用以下的HTTP head:

sendNotificationRequest.ContentTyp0e="text/xml";

sendNotificationRequest.Headers.Add("X-NotificationClass","<batchinginterval>");

String tileMessage="<?xml version=\"1.0\"encoding=/"utf-8"?>"+

"<root>"+

"<Value1>SomeUserValue<Value1>"+

"<Value2>SomeOtherUserValue<Value2>"+

"</root>";

 

Toast:特定的XML格式,如果程序正在運行,則直接將內容傳遞給程序,觸發ShellToastNotificationReceived事件;如果程序沒有運行,系統將顯示toast的彈出通知,顯示Toast消息內容

使用以下的HTTP head:

sendNotificationRequest.ContentTyp0e="text/xml";

sendNotificationRequest.Headers.Add("X-WindowsPhone-Target","toast");

sendNotificationRequest.Headers.Add("X-NotificationClass","<batchinginterval>");

String toastMessage="<?xml version=\"1.0\"encoding=\"utf-8\"?>"+

"<wp:Notificationxmlns:wp=\"WPNotification\">"+

"<wp:Toast>"+

"<wp:Text1>WEATHER ALERT </wp:Text1>"+

"<wp:Text2>Stormy</wp:Text2>"+

"<wp:Param>/page1.xaml?value1=1234<wp:Param>"+

"</wp:Toast>"+

"</wp:Notification>";

Tile:特定XML格式,不會傳遞給應用,如果應用圖標被固定在開始屏幕,在系統將更新通知消息的內容

發佈了28 篇原創文章 · 獲贊 3 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章