关闭应用程序后,我的应用程序会很好地接收推送通知。但是当应用程序运行时,我什么也没得到。这是我在以前的应用程序中使用的相同代码,没有任何问题,这些问题在WindowsPhone8上,而新应用程序在WindowsPhone8.1设备上运行。
制作原始应用程序时,我使用了此Push Tutorial。如果您想在应用程序打开时收到通知,我确实会说添加此行。
如果8.1更新对推送通知有所帮助,那将是一件好事。其他任何东西也将不胜感激。
HttpNotificationChannel pushChannel;
string channelName = "PushChannel";
pushChannel = HttpNotificationChannel.Find(channelName);
//Push Notifications
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
//// 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...
void PushChannel_ShellToastNotificationReceived(object sender,
NotificationEventArgs e)
{
string relativeUri = string.Empty;
// Parse out the information that was part of the message.
foreach (string key in e.Collection.Keys)
{
if (string.Compare(
key,
"wp:Param",
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.CompareOptions.IgnoreCase) == 0)
{
relativeUri = e.Collection[key];
}
}
}
罗布·卡普兰:
当应用程序处于前台时,不会显示吐司。如果需要,该应用程序应显示自己的UI(您的代码段不显示任何内容)。这就是ShellToastNotificationReceived事件的用途:它在到达Toast通知而不是显示Toast时触发。您是否可以确定在敬酒时未引发ShellToastNotificationReceived?它应该是。您能否确认它已在调试器中注册并接收(或未收到)?请参阅msdn.microsoft.com/en-us/library/windows/apps/…
我:
在8.1更新之前,当打开的应用收到推送时,吐司仍然会显示。我只是进行了一些测试,而且可以肯定的是,“ PushChannel_ShellToastNotificationReceived”事件仍在触发,但是吐司没有显示。我想这只是意味着我需要处理不同的事情。如果您想把它变成答案,我可以奖励它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句