【发布时间】:2017-01-13 09:01:32
【问题描述】:
在我当前的 UWP 项目中,试图通过原始推送通知触发 OnBackgroundActivated()。报名如下:
var builder = new BackgroundTaskBuilder();
builder.Name = taskName;
builder.SetTrigger(new PushNotificationTrigger());
BackgroundTaskRegistration task = builder.Register();
当应用程序附加到 Visual Studio 并处于“恢复”状态(活动)时,当我发送原始通知时会调用 OnBackgroundActivated()。我可以看到使用 System.Diagnostics.Debug.WriteLine()。
当应用程序附加到 Visual Studio 并处于“暂停”状态(未激活)时,不会调用 OnBackgroundActivated()。但是,一旦我将状态更改回“恢复”,OnBackgroundActivated() 就会使用我在应用程序未激活时发送的原始通知调用。就像原始通知会排队,直到应用再次激活。
为什么在应用不活动时 OnBackgroundActivated() 不立即触发?我认为这是此功能的主要目的。
【问题讨论】:
-
你在用这个OnBackgroundActivated method吗?你用single process model实现
PushNotificationTrigger吗? -
是的,单进程模型。
-
我无法重现您的问题。在我这边,即使我将生命周期管理事件更改为“暂停”,
OnBackgroundActivated方法也会被调用。您使用的操作系统版本是什么?您能否分享一个可以重现您的问题的minimal reproducible example?
标签: c# background uwp push