我的应用怎么能收到吐司呢?

本文关键字:吐司 应用 怎么能 我的 | 更新日期: 2023-09-27 18:10:27

我遵循Jeff的教程并在我的应用程序中实现了推送。

HttpNotificationChannel channel;
void GetPushChannel()
{
    channel = new HttpNotificationChannel("BLANKENSOFT_" + DateTime.Now.Ticks.ToString());
    channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(channel_ChannelUriUpdated);
    channel.Open();
}
void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
    Dispatcher.BeginInvoke(delegate
    {
        URIBlock.Text = channel.ChannelUri.ToString();
    });
}

所以我现在可以在我的应用程序中获取和处理推送通知。但当我的应用关闭时,我想要显示发生了什么事,该怎么办?

我想到了ScheduledTaskAgent,但是它们受到活动时间的限制…如果在代理未运行时发送通知怎么办?还是无所谓?

我想在ScheduledTaskAgent中实现上述相同的功能。

我的应用怎么能收到吐司呢?

您可以参考示例http://code.msdn.microsoft.com/wpapps/Toast-Notification-Sample-fb20ae13。当应用程序关闭并从服务器端发送通知时,它将在设备上接收,不需要任何ScheduledTaskAgent或后台进程。WP推送通知的有效载荷如下:

<?xml version='1.0' encoding='utf-8'?>
<wp:Notification xmlns:wp='WPNotification'>
  <wp:Toast>
    <wp:Text1>Title of application</wp:Text1>
    <wp:Text2>Subtitle for application</wp:Text2>
    <wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param> //supported from WP7.1 
  </wp:Toast>
</wp:Notification>

In负载是从WP7.1中包含的,它用于在应用程序关闭时收到toast通知时将用户导航到特定的页面。此外,如果您想在应用程序关闭和toast到达时显示任何自定义消息,请将其导航到特定页面并显示带有自定义消息的消息框。

这是我认为你想知道的,如果不是让我知道。由于

添加

pushChannel.BindToShellToast();