Windows 10 移动应用程序扩展执行不断被拒绝
Windows 10 Mobile App Extended Execution keeps getting denied
我正尝试在我的 Windows 10 UWP 应用程序上使用扩展执行来进行位置跟踪。网上有很多这样的例子。我基本上是在使用这个通用代码块。
using (var session = new ExtendedExecutionSession())
{
session.Reason = ExtendedExecutionReason.LocationTracking;
session.Description = "Tracking your location";
session.Revoked += NewSession_Revoked;
var result = await session.RequestExtensionAsync();
switch (result)
{
case ExtendedExecutionResult.Allowed:
await StartLocationTrackingAsync();
break;
default:
case ExtendedExecutionResult.Denied:
//Notify user or log this.
break;
}
}
此代码块在我的应用程序的挂起事件处理程序中执行,如下所示:
public Scenario1()
{
this.InitializeComponent();
Application.Current.Suspending += Current_Suspending;
}
private async void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
//Do my extended execution request here.
}
我遇到的第一个问题是我什至无法触发该事件,但我读到 VS 不会在调试时暂停您的应用程序。所以,我强迫它暂停使用 VS 中的生命周期事件下拉列表。现在,我每次都能引发暂停事件,这很好。
但是,当我请求延长执行会话时,每次都被拒绝。我已经在模拟器和我的物理 W10 移动设备上尝试过多次,每次都被拒绝。
这是为什么?我怎样才能让它被允许?
谢谢!
假设您已经在应用程序清单中声明了 Location,您将必须 运行 前台的代码 ,这意味着它将在您的 MainPage_Loaded
回调中工作,但在暂停状态下 不会 。
A location tracking extended execution session can run as long as
needed. However, there can only be one such session running per
device. A location tracking extended execution session can only be
requested in the foreground, and the app must be in the Running state.
This ensures that the user is aware that the app has initiated an
extended location tracking session.
后台要运行这个,看这个-
It is still possible to use the
GeoLocator while the app is in the background by using a background
task, or an app service, without requesting a location tracking
extended execution session.
当您使用 LocationTracking
扩展执行时 -
Specify ExtendedExecutionReason.LocationTracking when you create an
ExtendedExecutionSession if your app needs to regularly log the
location from the GeoLocator. Apps for fitness tracking and navigation
that need to regularly monitor the user's location and should use this
reason.
这是full article。
我正尝试在我的 Windows 10 UWP 应用程序上使用扩展执行来进行位置跟踪。网上有很多这样的例子。我基本上是在使用这个通用代码块。
using (var session = new ExtendedExecutionSession())
{
session.Reason = ExtendedExecutionReason.LocationTracking;
session.Description = "Tracking your location";
session.Revoked += NewSession_Revoked;
var result = await session.RequestExtensionAsync();
switch (result)
{
case ExtendedExecutionResult.Allowed:
await StartLocationTrackingAsync();
break;
default:
case ExtendedExecutionResult.Denied:
//Notify user or log this.
break;
}
}
此代码块在我的应用程序的挂起事件处理程序中执行,如下所示:
public Scenario1()
{
this.InitializeComponent();
Application.Current.Suspending += Current_Suspending;
}
private async void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
//Do my extended execution request here.
}
我遇到的第一个问题是我什至无法触发该事件,但我读到 VS 不会在调试时暂停您的应用程序。所以,我强迫它暂停使用 VS 中的生命周期事件下拉列表。现在,我每次都能引发暂停事件,这很好。
但是,当我请求延长执行会话时,每次都被拒绝。我已经在模拟器和我的物理 W10 移动设备上尝试过多次,每次都被拒绝。
这是为什么?我怎样才能让它被允许?
谢谢!
假设您已经在应用程序清单中声明了 Location,您将必须 运行 前台的代码 ,这意味着它将在您的 MainPage_Loaded
回调中工作,但在暂停状态下 不会 。
A location tracking extended execution session can run as long as needed. However, there can only be one such session running per device. A location tracking extended execution session can only be requested in the foreground, and the app must be in the Running state. This ensures that the user is aware that the app has initiated an extended location tracking session.
后台要运行这个,看这个-
It is still possible to use the GeoLocator while the app is in the background by using a background task, or an app service, without requesting a location tracking extended execution session.
当您使用 LocationTracking
扩展执行时 -
Specify ExtendedExecutionReason.LocationTracking when you create an ExtendedExecutionSession if your app needs to regularly log the location from the GeoLocator. Apps for fitness tracking and navigation that need to regularly monitor the user's location and should use this reason.
这是full article。