Windows 10 Mobile(10.0.14393)地理围栏的背景任务(LocationTrigger)

时间:2016-08-26 13:47:11

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

10.0.14393(Anniversery Update)以来,LocationTrigger似乎无效。我有:

  • Windows Phone 8.1应用程序(也适用于UWP应用程序)。
  • 输出到Windows Runtime Component库的可移植库(.winmd
  • 带有位置功能的后台任务声明(设置为库作为条目)。
  • 使用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 Mobile。到目前为止有没有已知的解决方案?

1 个答案:

答案 0 :(得分:0)

我也有这样的问题,但是使用简单的TimeTrigger任务。任务注册没有任何错误,它在" Lifecycle Events" Visual Studio,但它不是在预定时间开始的。通常,但并非总是如此,有助于后续步骤。

  1. 拒绝访问应用程序以在Windows设置中在后台运行
  2. 重启设备
  3. 允许访问
  4. 运行应用以注册任务
  5. 在将通用Windows应用开发工具更新到版本1.4.1后,问题已经开始,但我不确定这一点。

相关问题