简体   繁体   中英

Location services broken in iOS 8

I have an app that want to get user location. As you may know, Apple change user private policy (as i suggest) and, now i can't get user location. It show no error, no warning, nothing. In attempt to fix this i add following code before calling [_locationManager startUpdatingLocation]; There it is:

CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus];

    if (authStatus == kCLAuthorizationStatusNotDetermined) {
        [_locationManager requestWhenInUseAuthorization];
        NSLog(@"Case 1");
        return;
    };

    if (authStatus == kCLAuthorizationStatusDenied || authStatus == kCLAuthorizationStatusRestricted) {
        // show an alert
        NSLog(@"Case 2");
        return;
    };

And output is Case 1, which mean - authStatus == kCLAuthorizationStatusNotDetermined . But there is no alert, no prompt, no suggestion to user to enable location services for my app. Actually, i even turn it on manually in settings of my iPhone. Still, not working (it work perfectly before Xcode update).

How to fix that? Any advices would be appreciated, thanks!

You need to add a reasoning in your info.plist as to why you are going to request a users location.

Open info.plist add a row with a key of NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription , a type of String, and for the value type in why you want to request the users location. For example, "Uses location to calculate the sunrise and sunset". iOS will not ask a user for permission to use their location unless you have given a reason as to why you are requesting it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM