Why requestWhenInUseAuthorization doesn't prompt the user for access to the location?

Objective CXcodeIos8Cllocationmanager

Objective C Problem Overview


In my viewDidLoad method I have

locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
    
    
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [locationManager requestWhenInUseAuthorization];
}

And the request is called, but the user is not prompted? Why?

Objective C Solutions


Solution 1 - Objective C

You probably need to update your plist file. Here's a tutorial how to do it, quick & dirty:

You need to do is to add one of the following keys to your Info.plist file:

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

You also need to request authorization for the corresponding location method, WhenInUse or Background. Use one of these calls:

[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]

There's also a post that I found helpful:

https://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8

This answer details how to update your plist file:

> Add one of the following lines to your info.plist > > > > NSLocationWhenInUseUsageDescription > The spirit of stack overflow is coders helping coders >
> NSLocationAlwaysUsageDescription > I have learned more on stack overflow than anything else

You'll probably want to customize and spell-check the strings of the dictionary entry that goes in the info.plist file before shipping the code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionspen123View Question on Stackoverflow
Solution 1 - Objective CAdrianView Answer on Stackoverflow