应用程序打开时不显示PUSH

本文关键字:显示 PUSH 应用程序 | 更新日期: 2023-09-27 18:28:13

当应用程序关闭时,我的应用程序会很好地接收推送通知。但当应用程序运行时,我什么也得不到。这与我在以前的应用程序中使用的代码相同,没有任何问题,这些应用程序在WindowsPhone8上,新应用程序在Windows Phone8.1设备上运行。

当我制作最初的应用程序时,我使用了这个推送教程。我确实有一行写着,如果你想在应用程序打开时收到通知,请添加此项。

如果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];
        }

    }
}

应用程序打开时不显示PUSH

Rob Caplan:

当应用程序处于前台时,预计不会显示Toast。如果需要的话,该应用程序应该显示自己的UI(你的代码片段没有显示任何内容)。这就是ShellToastNotificationReceived事件的作用:当toast通知到达而不是toast出现时,它会触发。你能确认ShellToastNotificationReceived在你期待吐司的时候没有被引发吗?应该是。你能确认它已经注册并在调试器中收到(或没有)吗?请参阅msdn.microsoft.com/en-us/library/windows/apps/…

我:

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