【问题标题】:UWP OnBackgroundActivated with PushNotificationTrigger (raw notification)UWP OnBackgroundActivated 与 PushNotificationTrigger(原始通知)
【发布时间】: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


【解决方案1】:

聚会迟到了,但也许这会为某人节省 2 天时间。我遇到了同样的问题,我的解决方法是将 appxmanifest 中的目标设备系列更改为最低 14393。

改变

<TargetDeviceFamily Name="Windows.Mobile" MinVersion="10.0.10586.0" MaxVersionTested="10.0.10586.0" />

<TargetDeviceFamily Name="Windows.Mobile" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />

适用于所有节点。奇怪的是,如果您不使用特定的设备系列,而是使用通用,那么您可以将其保留在 10.0.00000.0 上并且它可以工作。

【讨论】:

    猜你喜欢
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    相关资源
    最近更新 更多