【问题标题】:Windows 10 Mobile (10.0.14393) Background Task for Geofence (LocationTrigger)Windows 10 移动版 (10.0.14393) 地理围栏后台任务 (LocationTrigger)
【发布时间】:2016-08-26 13:47:11
【问题描述】:

自从10.0.14393(周年纪念更新)以来,LocationTrigger 似乎不起作用。我有:

  • Windows Phone 8.1 应用程序(也适用于 UWP 应用程序)。
  • 输出到 Windows Runtime Component 库 (.winmd) 的可移植库
  • Background Task 的声明具有 Location 功能(设置为库作为条目)。
  • 使用BackgroundExecutionManager.RequestAccessAsync() 访问
  • LocationTrigger 类型为 Geofence

永远不会触发后台任务。获取权限后的注册/任务码:

public sealed class GeofenceTask : IBackgroundTask
{
    public static void Register()
    {
        var taskName = nameof(GeofenceTask);

        foreach (var n in BackgroundTaskRegistration.AllTasks.Where(n => n.Value.Name == taskName))
        {
            n.Value.Unregister(true);
            break;
        }

        var builder = new BackgroundTaskBuilder {Name = taskName, TaskEntryPoint = typeof (GeofenceTask).FullName};
        builder.SetTrigger(new LocationTrigger(LocationTriggerType.Geofence));
        builder.Register();
    }

    public void Run(IBackgroundTaskInstance taskInstance)
    {
        // Do magic.
    }
}

在 Windows Phone 8.1 设备或模拟器上运行有效。预更新,它也适用于 Windows 10 移动版。到目前为止有没有已知的解决方案?

【问题讨论】:

标签: c# cordova windows-phone uwp windows-10-mobile


【解决方案1】:

我也有这样的问题,但使用简单的 TimeTrigger 任务。任务注册没有任何错误,它在 Visual Studio 的“生命周期事件”中可见,但它没有在预定时间开始。通常,但并非总是如此,有助于下一步。

  1. 在 Windows 设置中拒绝访问在后台运行的应用
  2. 重启设备
  3. 允许访问
  4. 运行应用注册任务

在将通用 Windows 应用开发工具更新到 1.4.1 版后,问题开始出现,但我不确定这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多