Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xamarin forms permission to use location iOS

I'm using Xamarin.Forms and creating an iOS App who has a background service to get a location each 10 minutes.

The code is working, my problem is when I access the App configuration on an IPad. It shows the permission for accesss the camera but not to access the current location.

I think that will be a problem when I submit the App for review.

For initialize the location:

this.locMgr = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
    locMgr.RequestAlwaysAuthorization(); // works in background
    //locMgr.RequestWhenInUseAuthorization (); // only in foreground
}

For getting the location:

if (CLLocationManager.LocationServicesEnabled) 
{
    if (CLLocationManager.Status==CLAuthorizationStatus.Authorized 
     || CLLocationManager.Status==CLAuthorizationStatus.AuthorizedAlways)
    {
        //set the desired accuracy, in meters
        LocMgr.DesiredAccuracy = 1;
        LocMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
        {
            _currentLocation = (e.Locations[e.Locations.Length - 1]);
        };

        LocMgr.AuthorizationChanged += (object sender, CLAuthorizationChangedEventArgs e) =>
        {
            if (e.Status == CLAuthorizationStatus.Denied 
             || e.Status == CLAuthorizationStatus.Restricted)
            {
                LocMgr.StopUpdatingLocation();
                _currentLocation = null;
            }
        };

        LocMgr.StartUpdatingLocation();
    }
}

There are something that I forgot?

like image 908
Luigi Maestrelli Avatar asked Nov 29 '25 12:11

Luigi Maestrelli


1 Answers

Did you add these keys to your Info.plist file?

<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message goes here</string>
like image 72
Guilherme Waltricke Avatar answered Dec 02 '25 01:12

Guilherme Waltricke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!