技术开发 频道

Windows Phone 7 开发之:推送通知

  从推送通知服务(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_ChannelUriUpdated);

  channel.Open();

  }

  void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)

  {

  Dispatcher.BeginInvoke(delegate

  {

  URIBlock.Text = channel.ChannelUri.ToString();

  });

  }

  在这个例子中我得到的URI是这样的:

http://sn1.notify.live.net/throttledthirdparty/01.00/AAHsLicyiJgtTaiDbJoSgmFiAgAAAAADAwAAAAQUZm52OjlzOEQ2NDJDRkl5MEVFMEQ

 

  一旦你有了URI,就可以在Web Service中保存它了。Web Service会初始化将要发送到你手机上的信息,我们有3种方法来实现:瓷砖(Tile)通知,吐司(Toast)通知和原生通知。

0
相关文章