【发布时间】:2015-10-30 12:29:33
【问题描述】:
每当我尝试在 windows phone 7 和 windows phone 8 中创建推送通知时,我的代码都可以正常工作,但每当我尝试在 windows phone 8.1 上构建相同的代码时,它都会显示“System.NullReferenceException”在生成 Chanal Uri 时发生在 Windows Phone 8.1 中。
代码如下:
String channelUri="XYZ";
HttpNotificationChannel myPushChannel = HttpNotificationChannel.Find(channelUri);
if (null == myPushChannel)
{
myPushChannel = new HttpNotificationChannel(channelUri);
myPushChannel.Open();
myPushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myPushChannel_ShellToastNotificationReceived);
myPushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(myPushChannel_ChannelUriUpdated);
myPushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(myPushChannel_ErrorOccurred);
myPushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(myPushChannel_HttpNotificationReceived);
myPushChannel.BindToShellTile();
myPushChannel.BindToShellToast();
uri = myPushChannel.ChannelUri;
}
else
{
if (myPushChannel != null)
{
myPushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myPushChannel_ShellToastNotificationReceived);
myPushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(myPushChannel_ChannelUriUpdated);
myPushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(myPushChannel_ErrorOccurred);
myPushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(myPushChannel_HttpNotificationReceived);
uri = myPushChannel.ChannelUri;
if (!myPushChannel.IsShellToastBound)
myPushChannel.BindToShellToast();
if (!myPushChannel.IsShellTileBound)
myPushChannel.BindToShellTile();
}
}
}
在 windows phone 7/8 上一切正常,但在 windows phone 8.1 上却不行。
【问题讨论】:
-
投票再次关闭作为重复。
标签: windows-phone-7 windows-phone-8 windows-phone-8.1