App打开时PUSH没有显示

Sei*_*ige 14 .net c# windows-phone-8 windows-phone-8.1

应用程序关闭时,我的应用程序会很好地接收推送通知 但是当应用程序运行时,我什么都没得到.这是我与出任何问题之前的应用程序都使用相同的代码,那些在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];
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

Sei*_*ige 2

罗布·卡普兰:

\n\n

当应用程序位于前台时,预计不会显示 Toast。如果需要,应用程序预计会显示自己的 UI(您的代码片段不显示任何内容)。这就是 ShellToastNotificationReceived 事件的用途:当 Toast 通知到达而不是 Toast 显示时触发。您能否确认当您期望 toast 时 ShellToastNotificationReceived 不会引发?它应该是。您能否确认它已在调试器中注册并接收(或未接收)?请参阅 msdn.microsoft.com/en-us/library/windows/apps/\xe2\x80\xa6

\n\n

我:

\n\n

在 8.1 更新之前,当打开的应用程序收到推送时,Toast 仍然会显示。我刚刚做了一些测试,果然,“PushChannel_ShellToastNotificationReceived”事件仍在被触发,但 toast 没有显示。我想这只是意味着我需要以不同的方式处理它。如果你想把它变成答案,我可以奖励它。

\n