六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 787|回复: 0

Windows Phone开发学习指南

[复制链接]

升级  32%

32

主题

32

主题

32

主题

秀才

Rank: 2

积分
98
 楼主| 发表于 2013-2-4 01:31:14 | 显示全部楼层 |阅读模式
本文和大家一起学习一下Windows Phone开发的概念,PushNotification是windowsphone7中的特色功能之一,它为手机端应用和webservice之间建立了一条专用的、持久的、稳定的通道来推送通知。当通道建立后,手机端应用可以接收webservice的任何信息。
一起学Windows Phone开发
一.简介
PushNotification是windowsphone7中的特色功能之一,这个功能可以变相的让普通开发者实现多任务(尽管并不是真正的多任务)。它为手机端应用和webservice之间建立了一条专用的、持久的、稳定的通道来推送通知。当通道建立后,手机端应用可以接收webservice的任何信息。


二.分类
对于PushNotification主要有三种:
1.TileNotification:
是可以改变QuickLanucharea内的图标内容(图片,文字等)的方式。不过这个需要把程序pintostart,才可以使用。
2.ToastNotification:
是在屏幕上面可以显示一个提示栏的方式。当点击提示栏可以打开应用程序。
3.RawNotification:
是直接使用Http方式来接收(httppolling)通知的方式。并且是不可见的,以后台方式传送通知。
对于以上几种通知,都需要一个服务端以pushnotification方式来发送通知,也就是说要使用pushnotification都需要一个服务端。
三.Windows Phone开发中创建服务器端
对于服务器端来说,发送不同的通知,都是以Http方式发出去的,但是在发送时,需要配置相应的参数,来告诉PushNotificationService所发送的类型是什么。
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:

  • "Content-Type:text/xml\r\nX-WindowsPhone-Target:token\r\n\r\n"  

  • <?xmlversionxmlversion="1.0"encoding="utf-8"?>

  • <wp:Notificationxmlns:wpwp:Notificationxmlns:wp="WPNotification">

  • <wp:Tile>

  • <wp:BackgroundImage>

  • <backgroundimagepath>

  • </wp:BackgroundImage>

  • <wp:Count>

  • <count>

  • </wp:Count>

  • <wp:Title>

  • <title>

  • </wp:Title>

  • </wp:Tile>

  • </wp:Notification>



2.Tokennotification:
request.Headers["X-WindowsPhone-Target"]="token";
request.Headers[X-NotificationClass]
Message:

  • “Content-Type:text/xml\r\nX-WindowsPhone-Target:toast\r\n\r\n”  

  • <?xmlversionxmlversion="1.0"encoding="utf-8"?>

  • <wp:Notificationxmlns:wpwp:Notificationxmlns:wp="WPNotification">

  • <wp:Toast>

  • <wp:Text1>

  • <string>

  • </wp:Text1>

  • <wp:Text2>

  • <string>

  • </wp:Text2>

  • </wp:Toast>

  • </wp:Notification>


3.rawnotification
request.Headers[X-NotificationClass]

request.BeginGetRequestStream();
StreamrequestStream=request.EndGetRequestStream();
requestStream.BeginWrite(message);

Response数据
response.StatusCode//Ok表示成功,否则可以查下面相应的错误码表,同时也可以查表得到当前状态
response.Headers[X-MessageID]
response.Headers[X-DeviceConnectionStatus]
response.Headers[X-SubscriptionStatus]
response.Headers[X-NotificationStatus






四.Windows Phone开发中创建客户端
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);
对于Tilenotification是由系统来接收的,所以这里没有相应的Event.
以上就是pushnotification的一些基本步骤,具体的实例在WP7TrainningKit里有。

<DIV align=right>【责任编辑:程华权 TEL:(010)68476606】
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表