Reputation: 3716
I have added the location permission feature in my project and the permission alert is working fine on ios simulators. But in a real iPhone device, permission is not asking.
I have added the location permissions in the info.plist file like below.
The app settings page shows all the other permission details except the location.
My Code:
public async void ShareLocation()
{
var status = await Permissions.RequestAsync<Permissions.LocationAlways>();
if (status == PermissionStatus.Granted)
{
//Actions
}
}
Reference: Xamarin Forms: How to check if GPS is on or off in Xamarin ios app?
Upvotes: 0
Views: 980
Reputation: 18861
In iOS 13, Apple made a big changes in location permission’s behaviour, especially for Always Allow permission.
In Xamarin.Forms you could use the plugin Permissions Plugin from nuget .
try
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync<LocationPermission>();
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
{
await DisplayAlert("Need location", "Gunna need that location", "OK");
}
status = await CrossPermissions.Current.RequestPermissionAsync<LocationPermission>();
}
if (status == PermissionStatus.Granted)
{
//Query permission
}
else if (status != PermissionStatus.Unknown)
{
//location denied
}
}
catch (Exception ex)
{
//Something went wrong
}
By the way , what is the iOS version on your real device ? The key Privacy - Location Always and When In Use Usage Description is available after iOS 10.0 .Use this key if your iOS app accesses location information while running in the background. If your app only needs location information when in the foreground, use NSLocationWhenInUseUsageDescription instead.
Upvotes: 1