I have a .NET Framework 4.6.2 WPF app that uses Windows.Devices.Geolocation
API to get Latitude and Longitude on Windows 10. It uses the Microsoft.Windows.SDK.Contracts NuGet package, version 10.0.19041.1. It is able to get location information when "Allow desktop apps to access your location" is on in Location Privacy Settings.
The first time location information is requested I want to get the prompt for permission to use precise location if it is not enabled. I am calling RequestAccessAsync()
before calling GeoLocator.GetGeopositionAsync()
, but get no prompt.
I have tried making a sparse package with the Location capability enabled and registering it, and am able to get a package ID in the WPF app, but still get no prompt.
I have tried using System.Windows.Application.Current.Dispatcher.Invoke()
to run RequestAccessAsync()
on the UI thread as this says it must: https://learn.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.
But get no prompt.
I am thinking that the app needs be listed in the "Choose which apps can access your precise location" list in Location Privacy Settings for this to work. How do I do that?
I want to get the prompt for permission to use precise location if it is not enabled ...
You will no longer get a prompt. See my answer here for details.
What you should do is to prompt the user to change the setting himself/herself in the Settings app.