Reputation: 6981
I am having trouble requesting IOS Location permissions in Xamarin with the following code it works on IOS 15 and IOS 13 but never returns on IOS 14. I have found several places talking about it and using something like this but they are from 2020. Could something have changed recently to cause this issue again ?
while (true)
{
if (await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>() == PermissionStatus.Granted)
break;
_ = Permissions.RequestAsync<Permissions.LocationWhenInUse>();
await Task.Delay(1000);
}
Xamarin Essentials 1.7.0
Xamarin.Forms 5.0.0.2125
Upvotes: 1
Views: 1084
Reputation: 114975
You can't loop waiting for a specific outcome. iOS will show the request to the user once. Once they have answered, that is the answer; The only exception is if they select "allow once" - You will get location permission but next time your app is launched, it will be as if you haven't asked and the dialog will be shown again.
If the user grants permission then you can use location. If they deny permission then you can't - You either proceed without location or direct them to device settings for your app where they can grant location permission.
Obtaining the permission answer is asynchronous; It takes some time for the user to select a response. The await
handles this for you.
var permission = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>()
if (permission == PermissionStatus.Granted) {
// Great - you can use location 😀
} else {
// No location permission - You can't use it 😞
// You can check the value of permission to see if location was denied or is unavailable
}
Upvotes: 3