我开发了Windows Phone 8应用程序,并在其中实现了推送通知服务。 当我在Windows Phone模拟器中启动应用程序时,它会创建URI(从MPNS获取)并将其发送到数据库以便下次发送通知,但问题是,当我重新启动模拟器时,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 as App).phoneURI 并发送到数据库,但是当我重新启动模拟器时它会发生变化?
有时它会提供URI,有时它会抛出异常 TileNotificationClient.DLL中出现'System.NullReferenceException'类型的异常但在此行string strURI = pushChannel.ChannelUri.ToString();
上未在用户代码中处理
答案 0 :(得分:0)
模拟器的(imho)好的一面是,每次重新启动它时都会有一个干净整洁的系统。
Notifikation uri也不保证在真实设备上保持一致。您应该在应用程序设计中包含更改通道Uris。