[英]Push notification for windows phone 8 for getting URI
我已经开发了Windows Phone 8应用程序,并且已经在其中实现了推送通知服务。 当我在Windows Phone Emulator中启动Application时,它会创建URI(从MPNS中获取)并将其发送到数据库,以便下次发送通知,但是问题是,当我重新启动Emulator时,URI会更改 ,我想保留相同的URI。对于设备或仿真器,我该怎么办?
我生成URI的代码是
HttpNotificationChannel pushChannel;
string channelName = "TileSampleChannel";
InitializeComponent();
pushChannel = HttpNotificationChannel.Find(channelName);
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.Open();
pushChannel.BindToShellTile();
}
else
{
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
//System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
// MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
string strURI = pushChannel.ChannelUri.ToString();
(App.Current as App).phoneURI = strURI;
}
我选择了这个(App.Current作为App).phoneURI并发送到数据库,但是当我重新启动模拟器时它得到了更改?
有时它提供URI,有时则抛出异常。TileNotificationClient.DLL中发生了'System.NullReferenceException'类型的异常,但未在此行的用户代码中处理过 string strURI = pushChannel.ChannelUri.ToString();
模拟器的(恕我直言)好的一面是,每次重新启动系统时,您都会拥有一个全新,干净的系统。
通知uri也不能保证在真实设备上是一致的。 您应该在应用程序设计中合并更改频道的Uris。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.