2
pushChannel = HttpNotificationChannel.Find(channelName);
但每次運行應用程序時都會返回我null
。pushChannel在windows phone 8.1設備中始終爲空(推送通知)
它只在wp8中給windows phone 8.1設備中的null
註冊頻道。
pushChannel = HttpNotificationChannel.Find(channelName);
但每次運行應用程序時都會返回我null
。pushChannel在windows phone 8.1設備中始終爲空(推送通知)
它只在wp8中給windows phone 8.1設備中的null
註冊頻道。
如果它將推送頻道返回爲「null」,那麼您是否嘗試創建推送頻道?
// The name of our push channel.
string channelName = "ToastSampleChannel";
InitializeComponent();
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
######################################################################
pushChannel = new HttpNotificationChannel(channelName); <---- Create a channel if it doesn't exist
######################################################################
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.Open();
// Bind this new channel for toast events.
pushChannel.BindToShellToast();
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
pushChannel.ChannelUri.ToString()));
}
PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
的Debug.WriteLine( 「通道::」 + channel.Uri.ToString());
是的這是微軟我唯一使用的代碼。實際上這個代碼完全在wp8設備上,但在wp8.1設備中,pushchennel總是空的。 – 2014-10-21 09:58:10
@umashankar我可以確認相同的代碼在WP8.1上工作我也在使用它。檢查您的手機設置中是否禁用通知。 – kshitijgandhi 2014-10-21 10:03:54