Azure移动服务频道中出现Null异常
我正在windows phone上学习推送通知教程。开始时,推送通知没有问题 然而,几天后,我打开了编码,发现了这个错误:Azure移动服务频道中出现Null异常,azure,push-notification,azure-mobile-services,mpns,windows-phone-8,Azure,Push Notification,Azure Mobile Services,Mpns,Windows Phone 8,我正在windows phone上学习推送通知教程。开始时,推送通知没有问题 然而,几天后,我打开了编码,发现了这个错误: System.NullReferenceException was unhandled by user code HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=UtemFtmkDB StackTrace: at U
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=UtemFtmkDB
StackTrace:
at UtemFtmkDB.MainPage.ButtonSave_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.<OnMouseLeftButtonUp>b__3()
InnerException:
每当我从
:App.CurrentChannel.ChannelUri.ToString()检索数据时,我都会收到此错误。为什么?频道可能尚未达到“已连接”状态
检查:
CurrentChannel.ConnectionStatus == ChannelConnectionStatus.Connected
如果这是真的,那么ChannelUri应该有一个非空值。您需要连接到ChannelUriUpdated事件:
private void AcquirePushChannel()
{
CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");
if(null != CurrentChannel)
{
CurrentChannel.ChannelUriUpdated += CurrentChannelOnChannelUriUpdated;
}
else
{
CurrentChannel = new HttpNotificationChannel("MyPushChannel");
CurrentChannel.ChannelUriUpdated += CurrentChannelOnChannelUriUpdated;
CurrentChannel.Open();
CurrentChannel.BindToShellTile();
}
}
private void CurrentChannelOnChannelUriUpdated(object sender, NotificationChannelUriEventArgs args)
{
// you can now get the URI from args.ChannelUri
}
请注意,对于现有通道,通道uri也可能会更改。因此,无论是否创建新频道,都应该侦听ChannelUriUpdate事件
private void AcquirePushChannel()
{
CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");
if(null != CurrentChannel)
{
CurrentChannel.ChannelUriUpdated += CurrentChannelOnChannelUriUpdated;
}
else
{
CurrentChannel = new HttpNotificationChannel("MyPushChannel");
CurrentChannel.ChannelUriUpdated += CurrentChannelOnChannelUriUpdated;
CurrentChannel.Open();
CurrentChannel.BindToShellTile();
}
}
private void CurrentChannelOnChannelUriUpdated(object sender, NotificationChannelUriEventArgs args)
{
// you can now get the URI from args.ChannelUri
}