Requesting in use authorization shows no prompt

2019-09-07 05:25发布

问题:

I have

NSLocationWhenInUseUsageDescription

and

NSLocationAlwaysUsageDescription

defined in my Info.plist.

In my code I do

    if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [_locationManager requestWhenInUseAuthorization];
    }

    [_locationManager startUpdatingLocation];

And I don't get prompted on iOS8.

I did a clean reinstall in my simulator. On iOS7 without the 3 if block I get prompted.

Right after startUpdatingLocation I check [CLLocationManager authorizationStatus] which is 0- kCLAuthorizationStatusNotDetermined

How do I prompt iOS8 users?

回答1:

4 ios 8: Need configure it in info.plist,

key name as "NSLocationAlwaysUsageDescription" value as ""

key name as "NSLocationWhenInUseUsageDescription" value as ""

When you called:

[_locationManager requestWhenInUseAuthorization];

will be auto prompt.

Testing with simulator, you can click "Reset content and settings..." and prompt again.

Here is a demo : https://github.com/JNYJ/001PGWUcurrentWULF