08 wp7 push notification

740 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
740
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

08 wp7 push notification

  1. 1. Windows Phone 7<br />Li Jingnan / Wang Tao<br />2011-7-15<br />1<br />
  2. 2. 2 days<br />2<br />
  3. 3. about<br />anytao| Ethos<br /><ethos:Member<br /> id = “Wang Tao”<br /> msn = anytao@live.com<br />weibo = http://weibo.com/anytao<br />runat = “Senior System Architect”<br />/><br />Jason | Ethos<br /><ethos:Member<br /> id = “Li Jingnan”<br /> msn = zengnami@hotmail.com<br />weibo= http://weibo.com/jn1981<br />runat = “SE”<br />/><br />
  4. 4. about<br />http://book.anytao.net<br />
  5. 5. 08 Push Notification<br />Wang Tao / 2011-07-15<br />
  6. 6. Session Outline<br />overview<br />titles<br />toast<br />raw<br />notification service<br />
  7. 7. 3 kinds of notifications<br />Raw<br />notification message content is app-specific<br />delivered directly to app only if it’s running<br />Toast<br />specific xml schema<br />Content delivered to app if it’s running<br />If app is not running, system displays Toast popup using notification message content<br />Tile<br />specific xml schema<br />Never delivered to app<br />If user has pinned to app tile, system updates it using notification message content<br />7<br />
  8. 8. Raw<br />Raw<br />updates it using notification message content<br />8<br />
  9. 9. Toast<br />9<br />
  10. 10. Tile<br />10<br />
  11. 11. What is Push ?<br />
  12. 12. Push VS Pull<br />Server-Push<br />Client-Pull<br />
  13. 13. push notification(PN)<br />WP7提供的一种允许服务器主动向WP7客户端直接发送通知的机制<br />服务器端主动发起<br />发送的是“通知”<br />避免了Client-Pull通信模式的中多次轮询<br />更省电<br />更省网络流量<br />给用户制造一种“多任务”的感觉<br />便于创建高互动性的WP7网络应用程序(如IM)<br />13<br />
  14. 14. 3 notifications<br />Tile Notification<br />效果:更新Tile(瓷片)显示<br />格式:特定格式XML片段<br />无论应用程序当前是否运行都接收<br />Toast Notification<br />效果:弹出Toast提示,用户可点击以启动应用程序<br />格式:特定格式XML片段<br />只有当应用程序未运行时才接收<br />RAW Notification<br />效果:由应用程序控制<br />格式:自由格式二进制序列<br />只有当应用程序正在运行时才接收<br />14<br />
  15. 15. 3 notifications<br />14<br />15<br />New photos online!<br />Seattle, WA: Sunny and 85 degrees<br />15<br />
  16. 16. content<br />Sub-Title<br />Title<br />16<br />
  17. 17. PN & battery<br />低电量状态<br />只发送RAW通知<br />MPNS将根据设备电量状态决定是否将通知发送到设备<br />正常电量状态<br />发送所有通知<br />极低电量状态<br />不发送任何通知<br />17<br />
  18. 18. PNbasic<br />Client:<br />Windows Phone Device<br />Microsoft Push Notification Service (MPNS) <br />Provider:<br />Web Application /<br />Cloud Service<br />18<br />
  19. 19. PN process<br />Push client<br />Tile<br />Toast<br />Open Chanel<br />App<br />Open push channel<br />Return URI<br />Data to toast<br />Data to tile<br />Data to App<br />Return Chanel URI<br />MPNS<br />Your service<br />Send URI to server<br />Event<br />Send push data to client<br />19<br />Send push data to URI<br />
  20. 20. PN program model<br />建立服务端Web Service。<br />功能:<br />a)接收客户端Chanle URI并保存在列表中<br />b)向MPN S发送通知<br />建立WP7客户端端应用程序。<br />功能:<br />a)向MPNS注册Chanel<br />b)将Chanel URI提交给服务端<br />c)接收通知并处理、显示<br />20<br />
  21. 21. send notification<br />// <Notification Channel URI>在Chanel创建时由MPNS生成,是Chanel的唯一标识<br />stringsubscriptionUri = "<Notification Channel URI>";<br />HttpWebRequestsendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri); <br />//必须使用POST方法发送通知<br />sendNotificationRequest.Method= "POST"; <br />// 添加HTTP头X-MessageID作为消息标识(可选)<br />sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>"); <br />sendNotificationRequest.ContentLength= notificationMessage.Length; <br />// 设置要发送的通知内容<payload><br />byte[] notificationMessage = new byte[] {<payload>}; <br />using(Stream requestStream = sendNotificationRequest.GetRequestStream()) { requestStream.Write(notificationMessage, 0, notificationMessage.Length); } <br />//向MPNS发送通知并获取响应<br />HttpWebResponseresponse = (HttpWebResponse)sendNotificationRequest.GetResponse(); <br />//从响应的HTTP头中提取相关结果<br />stringnotificationStatus = response.Headers["X-NotificationStatus"]; <br />stringnotificationChannelStatus = response.Headers["X-SubscriptionStatus"]; <br />stringdeviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];<br />21<br />
  22. 22. tile notification<br />sendNotificationRequest.ContentType = "text/xml";<br />sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");<br />sendNotificationRequest.Headers.Add("X-NotificationClass", “1"); <br />22<br />tilenotification HTTPheader<br />tilenotification content<br />string tileMessage = "<?xml version="1.0" encoding="utf-8"?>" +<br />"<wp:Notificationxmlns:wp="WPNotification">" +<br /> "<wp:Tile>" +<br /> "<wp:BackgroundImage><background image path></wp:BackgroundImage>" +<br /> "<wp:Count><count></wp:Count>" +<br /> "<wp:Title><title></wp:Title>" +<br /> "</wp:Tile> " +<br />"</wp:Notification>";<br />
  23. 23. toast<br />sendNotificationRequest.ContentType = "text/xml";<br />sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");<br />sendNotificationRequest.Headers.Add("X-NotificationClass", “1");<br />23<br />Toast http header<br />Toast content<br />string toastMessage = "<?xml version="1.0" encoding="utf-8"?>" +<br />"<wp:Notificationxmlns:wp="WPNotification">" +<br /> "<wp:Toast>" +<br /> "<wp:Text1><string></wp:Text1>" +<br /> "<wp:Text2><string></wp:Text2>" +<br /> "</wp:Toast>" +<br />"</wp:Notification>";<br />
  24. 24. send notification<br />// <Notification Channel URI>在Chanel创建时由MPNS生成,是Chanel的唯一标识<br />stringsubscriptionUri = "<Notification Channel URI>";<br />HttpWebRequestsendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri); <br />//必须使用POST方法发送通知<br />sendNotificationRequest.Method= "POST"; <br />// 添加HTTP头X-MessageID作为消息标识(可选)<br />sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>"); <br />sendNotificationRequest.ContentLength= notificationMessage.Length; <br />// 设置要发送的通知内容<payload><br />byte[] notificationMessage = new byte[] {<payload>}; <br />using(Stream requestStream = sendNotificationRequest.GetRequestStream()) { requestStream.Write(notificationMessage, 0, notificationMessage.Length); } <br />//向MPNS发送通知并获取响应<br />HttpWebResponseresponse = (HttpWebResponse)sendNotificationRequest.GetResponse(); <br />//从响应的HTTP头中提取相关结果<br />stringnotificationStatus = response.Headers["X-NotificationStatus"]; <br />stringnotificationChannelStatus = response.Headers["X-SubscriptionStatus"]; <br />stringdeviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];<br />24<br />
  25. 25. raw notificaition<br />sendNotificationRequest.Headers.Add("X-NotificationClass", “1");<br />25<br />RAW http header<br />RAWhttp content<br />new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};<br />
  26. 26. demo<br />26<br />/ title<br />/ toast<br />/ raw<br />/ notification service<br />04 notification<br />
  27. 27. thank you<br />27<br />thank youwww.anytao.com<br />
  28. 28. 28<br />

×