Windows Phone 8 通知和后台任务 [英] Windows Phone 8 notifications and background tasks

查看:18
本文介绍了Windows Phone 8 通知和后台任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了官方论坛和文档以及所有其他地方,但无法找到具体的答案.

问.在 Windows Phone 8 中,应用程序是否可以在后台响应推送通知并执行任务?

据我所知,对于Toast 和 Tile 通知,当应用程序不在前台时,它根本没有任何钩子可以响应传入的消息.

我认为原始通知"是正确的选择,因为我不需要更新应用程序磁贴,甚至不需要显示 Toast 通知.但是,如果我能做到这一点,我一直无法找到示例或文档.

我找到了几个关于为 Windows 商店应用程序执行此操作的链接,但我想知道是否可以为 Windows Phone 8 执行此操作.>

我已经检查了另一个线程,

带有通知的 Windows Phone 8 后台任务

其中一个答案表明 Whatsapp 实际上有一个 hack,可以在收到推送通知后下载消息.那么,我的问题的答案是吗?

解决方案

这在 Windows Phone 8.1 中有所改变.来自 原始通知概述(Windows 运行时应用程序)

接收原始通知

您的应用可以通过两种途径获得原始数据通知:

  • 在您的应用程序运行时通过通知传递事件.
  • 如果您的应用能够运行后台任务,则通过原始通知触发的后台任务.

应用可以使用这两种机制来接收原始通知.如果一个应用实现通知传递事件处理程序和后台由原始通知触发的任务,通知当应用程序运行时,交付事件将优先.

  • 如果应用正在运行,通知传递事件将优先于后台任务,应用将有机会首先处理通知.
  • 通知传递事件处理程序可以通过将事件的 PushNotificationReceivedEventArgs.Cancel 属性设置为 true 来指定,一旦处理程序退出,原始通知不应传递到其后台任务.如果 Cancel 属性设置为 false 或未设置(默认值为 false),则原始通知将在通知传递事件处理程序完成其工作后触发后台任务.

I have searched the official forums and documentation and all other places, but haven't been able to find a concrete answer.

Q. In Windows Phone 8, is it possible for an application to respond to a Push Notification, and perform a task, while it is in the background?

As far as I can understand, for Toast and Tile Notifications, when the app is not in the foreground, there are no hooks at all for it to be able to respond to the incoming message.

I think "raw notifications" are the correct choice for this, since I am not required to update the app tile, or even show a Toast Notification. But, I haven't been able to find an example, or in the documentations, if I can do this.

I have found several links which talk about doing this for Windows store apps, but I want to find out if this can be done for Windows Phone 8.

I have checked this other thread,

Windows Phone 8 Background Task with notifications

Where one of the answer suggests that Whatsapp actually has a hack for this, to download the messages after a push notification is received. So, is the answer to my question, a NO?

解决方案

This has changed in Windows Phone 8.1. From Raw notification overview (Windows Runtime apps)

Receiving a raw notification

There are two avenues through which your app can be receive raw notifications:

  • Through notification delivery events while your application is running.
  • Through background tasks triggered by the raw notification if your app is enabled to run background tasks.

An app can use both mechanisms to receive raw notifications. If an app implements both the notification delivery event handler and background tasks that are triggered by raw notifications, the notification delivery event will take priority when the app is running.

  • If the app is running, the notification delivery event will take priority over the background task and the app will have the first opportunity to process the notification.
  • The notification delivery event handler can specify, by setting the event's PushNotificationReceivedEventArgs.Cancel property to true, that the raw notification should not be passed to its background task once the handler exits. If the Cancel property is set to false or is not set (the default value is false), the raw notification will trigger the background task after the notification delivery event handler has done its work.

这篇关于Windows Phone 8 通知和后台任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆