Cllocationmanager Authorization Issue iOS 8

CLLocationManager authorization issue iOS 8

It's an iOS 8 related issue. You have to put NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription keys in your .plist file (value may be an additional message that will be presented in location alert). These keys are required in iOS 8.

How it's said in Apple guidelines:

This key is required when you use the requestAlwaysAuthorization
method of the CLLocationManager class to request authorization for
location services. If this key is not present and you call the
requestAlwaysAuthorization method, the system ignores your request and
prevents your app from using location services.

Location Services not working in iOS 8

I ended up solving my own problem.

Apparently in iOS 8 SDK, requestAlwaysAuthorization (for background location) or requestWhenInUseAuthorization (location only when foreground) call on CLLocationManager is needed before starting location updates.

There also needs to be NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist with a message to be displayed in the prompt. Adding these solved my problem.

Sample Image

For more extensive information, have a look at: Core-Location-Manager-Changes-in-ios-8

CLLocationManager authorization message not show in ios iOS 8.0.1

In iOS8 you have to request the user to authorize the access by using requestWhenInUseAuthorization or requestAlwaysAuthorization.

And you have add either of the keys NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription with proper messages to the info.plist

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}

CLLocationManager.authorizationStatus() always CLAuthorizationStatus.NotDetermined with swift&objC app

Keep in mind that NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription keys are now mandatory, so you should include that in your plist.

prompting for location authorization in iOS8

The error message is quite self-explained.

First of all, you didn't initialized CLLocationManager in your viewDidLoad. You can initialize with (before the delegate line):

self.locationManager = [[CLLocationManager alloc] init];

Then, you have to request for location service, using [self.locationManager requestWhenInUseAuthorization] or [self.locationManager requestAlwaysAuthorization]. (Not to forget to add corresponding usage description key in Info.plist).

Last, you have to check the response of authorization from user. If user denied the authorization, you shouldn't start any Location Service-related actions, until you ask again.


Update if you support iOS 7 as well, the codes will be slightly different.



Related Topics



Leave a reply



Submit