问题
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 typeGeofence
.
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.
- Deny access to the app to run in background in Windows settings
- Restart device
- Allow access
- 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