Location Manager in iOS 8

The Core Location service in iOS 8 includes now two different modes of authorization: While Using the App and Always.

Location permissions

In our code application we must request the user to accept one of these modes.

  • When In Use. This mode allows your app to use the location services when the app is in the foreground.
    if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
       [self.locationManager requestWhenInUseAuthorization];
    
  • Always. This mode allows your app to use the location services when the app is in the foreground and in the background.
    if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
       [self.locationManager requestAlwaysAuthorization];
    

Finally, we have to add in the Info.plist file of our app the values for the keys NSLocationWhenInUseUsageDescription or/and NSLocationAlwaysUsageDescription. These values contain the messages that will be displayed to the user when requesting the authorization.

info.plist properties

Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.