如何将 WPF 应用程序添加到 Windows 10 中的 "Choose which apps can access your precise location" 列表?

How to add WPF app to "Choose which apps can access your precise location" list in Windows 10?

我有一个 .NET Framework 4.6.2 WPF 应用程序,它使用 Windows.Devices.Geolocation API 在 Windows 10 上获取纬度和经度。它使用 Microsoft.Windows.SDK.Contracts NuGet包,版本 10.0.19041.1。在位置隐私设置中打开“允许桌面应用程序访问您的位置”时,它能够获取位置信息。

第一次请求位置信息我想在未启用的情况下获得使用精确位置权限的提示。我在调用 GeoLocator.GetGeopositionAsync() 之前调用了 RequestAccessAsync(),但没有得到任何提示。

我已经尝试制作一个启用了定位功能的稀疏包并注册它,并且能够在 WPF 应用程序中获取包 ID,但仍然没有得到提示。

我已经尝试在 UI 线程上使用 System.Windows.Application.Current.Dispatcher.Invoke() 到 运行 RequestAccessAsync(),因为它必须:https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/get-location#step-1-request-access-to-the-users-location

You must call the RequestAccessAsync method from the UI thread and your app must be in the foreground.

但是没有得到提示。

我认为该应用程序需要列在位置隐私设置的“选择哪些应用程序可以访问您的精确位置”列表中才能运行。我该怎么做?

I want to get the prompt for permission to use precise location if it is not enabled ...

您将不再收到提示。详情见我的回答

您应该做的是提示用户在“设置”应用中更改设置himself/herself。