Windows phone 7 ';System.NullReferenceException';在Windows Phone 8.1中生成通道Uri时发生
每当我尝试在windows phone 7和windows phone 8中创建推送通知时,我的代码工作正常,但每当我尝试在windows phone 8.1上构建相同的代码时,它会显示“System.NullReferenceException”,即在windows phone 8.1中生成通道Uri时发生 代码如下:Windows phone 7 ';System.NullReferenceException';在Windows Phone 8.1中生成通道Uri时发生,windows-phone-7,windows-phone-8,windows-phone-8.1,Windows Phone 7,Windows Phone 8,Windows Phone 8.1,每当我尝试在windows phone 7和windows phone 8中创建推送通知时,我的代码工作正常,但每当我尝试在windows phone 8.1上构建相同的代码时,它会显示“System.NullReferenceException”,即在windows phone 8.1中生成通道Uri时发生 代码如下: String channelUri="XYZ"; HttpNotificationChannel myPushChannel =
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();
}
}
}
String channelUri=“XYZ”;
HttpNotificationChannel myPushChannel=HttpNotificationChannel.Find(channelUri);
如果(null==myPushChannel)
{
myPushChannel=新的HttpNotificationChannel(channelUri);
myPushChannel.Open();
myPushChannel.ShellToastNotificationReceived+=新事件处理程序(myPushChannel\u ShellToastNotificationReceived);
myPushChannel.ChannelUriUpdated+=新事件处理程序(myPushChannel\u ChannelUriUpdated);
myPushChannel.ErrorOccursed+=新事件处理程序(myPushChannel\u ErrorOccursed);
myPushChannel.HttpNotificationReceived+=新事件处理程序(myPushChannel\u HttpNotificationReceived);
myPushChannel.BindToShellTile();
myPushChannel.BindToShellToast();
uri=myPushChannel.ChannelUri;
}
其他的
{
如果(myPushChannel!=null)
{
myPushChannel.ShellToastNotificationReceived+=新事件处理程序(myPushChannel\u ShellToastNotificationReceived);
myPushChannel.ChannelUriUpdated+=新事件处理程序(myPushChannel\u ChannelUriUpdated);
myPushChannel.ErrorOccursed+=新事件处理程序(myPushChannel\u ErrorOccursed);
myPushChannel.HttpNotificationReceived+=新事件处理程序(myPushChannel\u HttpNotificationReceived);
uri=myPushChannel.ChannelUri;
如果(!myPushChannel.IsHelltoastBound)
myPushChannel.BindToShellToast();
如果(!myPushChannel.IsShellTileBound)
myPushChannel.BindToShellTile();
}
}
}
在windows phone 7/8中一切正常,但在windows phone 8.1中不正常。如果我们谈论的是WP8.1通用应用程序,而不是silverlight,您应该使用下面的行获取PushNotificationChannel:
PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
可能重复投票,以作为重复投票再次结束。