Windows 10 Mobile (10.0.14393) Background Task for Geofence (LocationTrigger)

别说谁变了你拦得住时间么 提交于 2019-12-07 10:06:02

问题


Ever since 10.0.14393 (Anniversery Update), LocationTrigger does not seem to work. I have:

  • A Windows Phone 8.1 application (also applies to a UWP application).
  • A portable library that ouputs to a Windows Runtime Component library (.winmd)
  • A declaration of Background Task with Location capabilities (set to the library as entry).
  • Access with BackgroundExecutionManager.RequestAccessAsync()
  • A LocationTrigger of type Geofence.

The background task is never triggered. Registration/task code after obtaining access:

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.
    }
}

Running on a Windows Phone 8.1 device or emulator works. Pre-update, it worked on Windows 10 Mobile, too. Is there any known solutions so far?


回答1:


I'm also having such issue but with simple TimeTrigger task. Task registered without any error, it visible in "Lifecycle Events" of Visual studio, but it not starts at scheduled time. Usually, but not always, helps next steps.

  1. Deny access to the app to run in background in Windows settings
  2. Restart device
  3. Allow access
  4. Run app to register tasks

The issue have start happen after update of Universal Windows App development tools to version 1.4.1, but I'm not sure on that point.



来源:https://stackoverflow.com/questions/39167898/windows-10-mobile-10-0-14393-background-task-for-geofence-locationtrigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!