IOS8 Location: How should I always ask for authorization after a user provides "When In Use" authorization?

When my application launches the map view, I request permission to host iOS8 "When In Use". Assume custom grants.

I would like to request Always permission only when the user selects a geo-setting function. But calling CLLocationManager.requestAlwaysAuthorization is not affected, since the current authorization status is no longer kCLAuthorizationStatusNotDetermined.

How would I request permission to “AFTER” AFTER the user provided When do you use the permission? I would think this is a common use case because applications should avoid asking for permission always if necessary.

+7
ios8 core-location
source share
2 answers

You're right, calling requestAlwaysAuthorization will not do anything if the user has already granted permission "when using". The workaround I used was to associate the user with the settings screen and let them enable the "Always" setting. Here are the steps for doing this:

  • Create a new key in app-Info.plist called NSLocationAlwaysUsageDescription and indicate some reasons why you should always ask permission in the value field.

    info.plist file

  • Associate your user with the settings screen of your application ( more details here )

     NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:settings]) [[UIApplication sharedApplication] openURL:settings]; 
  • As soon as the user hits your link, he will see the following:

    Initial settings screen

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

    Location access settings screen

  • Changes to monitor authorization in your application by implementing the delegation method CLLocationManager locationManager:didChangeAuthorizationStatus:
+3
source share

I don't know about objective-c, but it works fine for me in fast and iOS 8.4. Make sure you provide both keys in your info.plist file

 NSLocationAlwaysUsageDescription NSLocationWhenInUseUsageDescription // iOS 11 and up will require this key instead of AlwaysUsageDescription NSLocationAlwaysAndWhenInUsageDescription 

Then just call

 locationManager.requestAlwaysAuthorization() 

And make sure locationManager is an instance variable! The local variable will be ignored for some strange reason. Apple Documentation

+2
source share

All Articles