Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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?

share|improve this question
    
Is there a particular problem you're asking about or just that you think there may be an issue? – Sten Petrov Apr 27 at 20:36
    
It was a particular problem. I saw working in others Xamarin projects. But I could not find anything different in my project. Now, with the answer I works great. – Luigi Maestrelli Apr 29 at 1:06

1 Answer 1

up vote 2 down vote accepted

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>
share|improve this answer
    
Works, i didn't know that i need to add this. Thanks – Luigi Maestrelli Apr 29 at 1:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.