从推送通知服务(Push Notification Service)中获取定制的URI
非常感谢,微软将这部分内容做得非常简单。我们得使用Microsoft.Phone.Notification程序集,不过我还是得用10行代码来从推送通知服务中(PNS)获取一个定制的URI。首先,我得创建一个HttpNotificationChannel。它将自动与PNS通信(在另一个线程中),并且还得通过一个事件来捕获服务返回的内容。
HttpNotificationChannel channel;
void GetPushChannel()
{
channel = new HttpNotificationChannel("BLANKENSOFT_" + DateTime.Now.Ticks.ToString());
channel.ChannelUriUpdated += new EventHandler
channel.Open();
}
void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(delegate
{
URIBlock.Text = channel.ChannelUri.ToString();
});
}
在这个例子中我得到的URI是这样的:
一旦你有了URI,就可以在Web Service中保存它了。Web Service会初始化将要发送到你手机上的信息,我们有3种方法来实现:瓷砖(Tile)通知,吐司(Toast)通知和原生通知。