一.简介
Push Notification是windows phone 7中的特色功能之一,这个功能可以变相的让普通开发者实现多任务(尽管并不是真正的多任务)。它为手机端应用和webservice之间建立了一条专用的、持久的、稳定的通道来推送通知。当通道建立后,手机端应用可以接收webservice的任何信息。
二.分类
对于Push Notification主要有三种:
1.Tile Notification:
是可以改变Quick Lanuch area内的图标内容(图片,文字等)的方式。不过这个需要把程序pin to start,才可以使用。
2.Toast Notification:
是在屏幕上面可以显示一个提示栏的方式。当点击提示栏可以打开应用程序。
3.Raw Notification:
是直接使用Http方式来接收(http polling)通知的方式。并且是不可见的,以后台方式传送通知。
对于以上几种通知,都需要一个服务端以push notification方式来发送通知,也就是说要使用push notification都需要一个服务端。
三.创建服务器端
对于服务器端来说,发送不同的通知,都是以Http方式发出去的,但是在发送时,需要配置相应的参数,来告诉Push Notification Service所发送的类型是什么。
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.Toast notification:
request.Headers["X-WindowsPhone-Target"] ="toast";
request.Headers[X-NotificationClass]
Message :
"Content-Type: text/xml\r\nX-WindowsPhone-Target: token\r\n\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-NotificationClass]
Message:
“Content-Type: text/xml\r\nX-WindowsPhone-Target: toast\r\n\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-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]
四.创建客户端
HttpNotificationChannelhttpChannel =HttpNotificationChannel.Find(ChannelName);
httpChannel.Open();
//绑定notification
httpChannel.BindToShellToast();
httpChannel.BindToShellTile(uris);
//获取notification
channel URI
httpChannel.ChannelUriUpdated +=newEventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);
//获取Raw
notification
httpChannel.HttpNotificationReceived +=newEventHandler<HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived);
//获取Toast
notification
httpChannel.ShellToastNotificationReceived +=newEventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);
//获取Push
notification error message
httpChannel.ErrorOccurred +=newEventHandler<NotificationChannelErrorEventArgs>(httpChannel_ExceptionOccurred);
对于Tile notification是由系统来接收的,所以这里没有相应的Event.
以上就是push notification的一些基本步骤,具体的实例在WP7TrainningKit里有。
分享到:
相关推荐
提示:服务器端的天气应用程序使用WindowsPhone.Recipes.Push.Messasges.dll,封装了所有发送、从Microsoft Push Notification Services接受响应的业务逻辑和功能。更多信息请参考:...
推送通知包可帮助您轻松地将消息推送到Android,IOS,WindowsPhone,Chrome和Firefox设备。 安装 使用Composer: composer install 或者你可以做 composer require tawba/push-notification 如果您没有作曲家,可以...
Rpush - Ruby的推送通知服务支持Apple Push Notification Service, Google Cloud Messaging, Amazon Device Messaging and Windows Phone Push Notification Service。
具有Pushwoosh的PhoneGap Build Starter应用程序 ... #### WP8指南: ://www.pushwoosh.com/programming-push-notification/windows-phone/wp-additional-platforms/windows-phone-7-cordova-sdk-integration-guide/
notification-sdk-integration-for #### Android: : #### WP8: ://www.pushwoosh.com/programming-push-notification/windows-phone/wp-additional-platforms/windows-phone-cordova-sdk-integrati
PushSharp 实现了服务器端向移动客户端推送消息的库,支持 iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, 和 Windows 8 devices! 示例代码://Create our push ...
wp推送通知服务案例源码,Windows Phone 中的 Microsoft Push Notification Service 向第三方开发人员提供了一个弹性,专注,而且持续的渠道,使得开发人员可以从Web Service 向移动应用程序发送信息和更新。...
� 源代码完全开放,便于开发人员更清楚的把握实现细节,便于提高开发人员的技术水平,有利于开发 出 更具差异性的应用。 � 采用了对有限内存、电池和 CPU 优化过的虚拟机 Dalvik , Android 的运行速度比想象的要...
#Push Notification Starter Kit 该工具包是一个框架,可轻松将推送通知合并到 Windows、iOS 和 Android 等应用程序中。提高应用的持续率和递归率是重要的推送通知,但根据功能需求,实现复杂,开发成本高。使用这个...
任务2 – 创建 Windows® Phone 7 客户端应用程序 ............................. 24 任务3 – 创建 Notification Channel ................................. 29 任务4 –Push Notification Service的接受和处理...
通过使用Pushsafer,可以轻松地在Android,Windows 10或iOS设备上实时发送和接收推送通知。