应用程序关闭时,我的应用程序会收到推送通知。但是当应用程序运行时,我什么都没得到。这与我在之前的应用程序中使用的代码完全没有任何问题,这些代码在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];
}
}
}
答案 0 :(得分:2)
Rob Caplan:
当应用程序位于前台时,预计不会显示Toasts。如果需要,应用程序应显示自己的UI(您的代码段不显示任何内容)。这就是ShellToastNotificationReceived事件的用途:当Toast通知到达而不是出现Toast时,它会触发。您是否可以确认在预期吐司时未提出ShellToastNotificationReceived?它应该是。你能确认它是在调试器中注册和接收(或不是)吗?请参阅msdn.microsoft.com/en-us/library/windows/apps/...
我:
在8.1更新之前,当一个打开的应用程序收到PUSH时,toast仍会显示。我刚做了一些测试,果然,“PushChannel_ShellToastNotificationReceived”事件仍然被触发,但是吐司没有显示。我想这只是意味着我需要处理它不同。如果你想把它变成答案,我可以奖励它。