自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows Phone開發(fā)學(xué)習(xí)指南

移動(dòng)開發(fā)
Windows Phone開發(fā)的過(guò)程你是否了解,這里和大家分享一下,PushNotification是windowsphone7中的特色功能之一,這個(gè)功能可以變相的讓普通開發(fā)者實(shí)現(xiàn)多任務(wù)。

本文和大家一起學(xué)習(xí)一下Windows Phone開發(fā)的概念,PushNotification是windowsphone7中的特色功能之一,它為手機(jī)端應(yīng)用和webservice之間建立了一條專用的、持久的、穩(wěn)定的通道來(lái)推送通知。當(dāng)通道建立后,手機(jī)端應(yīng)用可以接收webservice的任何信息。

一起學(xué)Windows Phone開發(fā)

一.簡(jiǎn)介

PushNotification是windowsphone7中的特色功能之一,這個(gè)功能可以變相的讓普通開發(fā)者實(shí)現(xiàn)多任務(wù)(盡管并不是真正的多任務(wù))。它為手機(jī)端應(yīng)用和webservice之間建立了一條專用的、持久的、穩(wěn)定的通道來(lái)推送通知。當(dāng)通道建立后,手機(jī)端應(yīng)用可以接收webservice的任何信息。

 

二.分類

對(duì)于PushNotification主要有三種:

1.TileNotification:

是可以改變QuickLanucharea內(nèi)的圖標(biāo)內(nèi)容(圖片,文字等)的方式。不過(guò)這個(gè)需要把程序pintostart,才可以使用。

2.ToastNotification:

是在屏幕上面可以顯示一個(gè)提示欄的方式。當(dāng)點(diǎn)擊提示欄可以打開應(yīng)用程序。

3.RawNotification:

是直接使用Http方式來(lái)接收(httppolling)通知的方式。并且是不可見的,以后臺(tái)方式傳送通知。

對(duì)于以上幾種通知,都需要一個(gè)服務(wù)端以pushnotification方式來(lái)發(fā)送通知,也就是說(shuō)要使用pushnotification都需要一個(gè)服務(wù)端。

三.Windows Phone開發(fā)中創(chuàng)建服務(wù)器端

對(duì)于服務(wù)器端來(lái)說(shuō),發(fā)送不同的通知,都是以Http方式發(fā)出去的,但是在發(fā)送時(shí),需要配置相應(yīng)的參數(shù),來(lái)告訴PushNotificationService所發(fā)送的類型是什么。

HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(channelUri);

request.Method=WebRequestMethods.Http.Post;

request.ContentType="text/xml;charset=utf-8";

request.ContentLength=notificationmessage.Length;

request.Headers["X-MessageID"]=Guid.NewGuid().ToString();


1.Toastnotification:

request.Headers["X-WindowsPhone-Target"]="toast";

request.Headers[X-NotificationClass]


Message:

  1. "Content-Type:text/xml\r\nX-WindowsPhone-Target:token\r\n\r\n"  
  2.  
  3. <?xmlversionxmlversion="1.0"encoding="utf-8"?> 
  4.  
  5. <wp:Notificationxmlns:wpwp:Notificationxmlns:wp="WPNotification"> 
  6.  
  7. <wp:Tile> 
  8.  
  9. <wp:BackgroundImage> 
  10.  
  11. <backgroundimagepath> 
  12.  
  13. </wp:BackgroundImage> 
  14.  
  15. <wp:Count> 
  16.  
  17. <count> 
  18.  
  19. </wp:Count> 
  20.  
  21. <wp:Title> 
  22.  
  23. <title> 
  24.  
  25. </wp:Title> 
  26.  
  27. </wp:Tile> 
  28.  
  29. </wp:Notification> 
  30.  

 


2.Tokennotification:

request.Headers["X-WindowsPhone-Target"]="token";

request.Headers[X-NotificationClass]

Message:

  1. “Content-Type:text/xml\r\nX-WindowsPhone-Target:toast\r\n\r\n”  
  2.  
  3. <?xmlversionxmlversion="1.0"encoding="utf-8"?> 
  4.  
  5. <wp:Notificationxmlns:wpwp:Notificationxmlns:wp="WPNotification"> 
  6.  
  7. <wp:Toast> 
  8.  
  9. <wp:Text1> 
  10.  
  11. <string> 
  12.  
  13. </wp:Text1> 
  14.  
  15. <wp:Text2> 
  16.  
  17. <string> 
  18.  
  19. </wp:Text2> 
  20.  
  21. </wp:Toast> 
  22.  
  23. </wp:Notification> 
  24.  

 

3.rawnotification

request.Headers[X-NotificationClass]

 

request.BeginGetRequestStream();

StreamrequestStream=request.EndGetRequestStream();

requestStream.BeginWrite(message);


Response數(shù)據(jù)

response.StatusCode//Ok表示成功,否則可以查下面相應(yīng)的錯(cuò)誤碼表,同時(shí)也可以查表得到當(dāng)前狀態(tài)

response.Headers[X-MessageID]

response.Headers[X-DeviceConnectionStatus]

response.Headers[X-SubscriptionStatus]

response.Headers[X-NotificationStatus

 

 

 


四.Windows Phone開發(fā)中創(chuàng)建客戶端

HttpNotificationChannelhttpChannel=HttpNotificationChannel.Find(ChannelName);

httpChannel.Open();

//綁定notification

httpChannel.BindToShellToast();

httpChannel.BindToShellTile(uris);

 

//獲取notificationchannelURI

httpChannel.ChannelUriUpdated+=newEventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);

//獲取Rawnotification

httpChannel.HttpNotificationReceived+=newEventHandler<HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived);

//獲取Toastnotification

httpChannel.ShellToastNotificationReceived+=newEventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);

//獲取Pushnotificationerrormessage

httpChannel.ErrorOccurred+=newEventHandler<NotificationChannelErrorEventArgs>(httpChannel_ExceptionOccurred);

對(duì)于Tilenotification是由系統(tǒng)來(lái)接收的,所以這里沒有相應(yīng)的Event.

以上就是pushnotification的一些基本步驟,具體的實(shí)例在WP7TrainningKit里有。

 

責(zé)任編輯:佚名 來(lái)源: cnblogs.com
相關(guān)推薦

2010-07-15 15:39:51

Perl線程

2014-08-26 10:01:18

Windows Pho平臺(tái)開發(fā)指南

2010-07-21 11:04:44

Perl學(xué)習(xí)指南

2009-11-11 14:32:33

路由協(xié)議介紹

2010-07-29 09:31:28

Flex編程模型

2010-07-16 10:44:54

Perl數(shù)組

2011-08-23 10:29:13

LuaPlayer

2011-08-17 14:07:43

IOS開發(fā)Quartz 2D

2009-09-17 09:01:10

CCNA學(xué)習(xí)指南CCNA

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2013-04-16 17:02:50

Windows Pho概論

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2010-06-11 14:21:53

2014-12-11 17:55:05

程序員

2024-10-15 08:10:49

NotebookLMYouTube視頻AI

2012-05-23 15:46:39

數(shù)字羅盤
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)