Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 Location: How should one request Always Authorization after user has granted "When In Use" Authorization?

When my app launches the map view, I request the iOS8 "When In Use" location permission. Assume user grants that.

I would like to request the Always permission only when user opts-in to my geofencing feature. But calling CLLocationManager.requestAlwaysAuthorization has no effect because the current authorization status is no longer kCLAuthorizationStatusNotDetermined.

How would one go about requesting the Always permission AFTER user has granted When In Use permission? I would think this is a common use case because apps should avoid asking for the Always permission unless needed.

like image 543
mobileideafactory Avatar asked Aug 07 '14 17:08

mobileideafactory


1 Answers

You are right, calling requestAlwaysAuthorization will not do anything if the user already granted 'when in use' permission. A workaround I used was to link the user to the settings screen and let them turn on the 'Always' setting themselves. Here are the steps to do that:

  1. Create a new key in your app-Info.plist called NSLocationAlwaysUsageDescription and enter some reasons as to why you need to request the always permission in the value field.

    info.plist file

  2. Link your user to your app's settings screen (more info here)

    NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:settings])
        [[UIApplication sharedApplication] openURL:settings];
    
  3. Once the user taps your link they will see this:

    Initial settings screen

    and when they click on Location, they will be able to see both While Using the App and Always settings to choose from:

    Location access settings screen

  4. Monitor authorization changes in your app by implementing the CLLocationManager delegate method locationManager:didChangeAuthorizationStatus:
like image 93
ken Avatar answered Jun 10 '23 22:06

ken