简体   繁体   中英

Location Services Stop working after reinstall with iOS10

Location services stopped working after I uninstalled my iOS10 app. I have the description set up in the Info.plist so it confuses me why location services would stop working. The app does not show up in Settings->Privacy->Location Services

<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs to use your location so that it may send it to your selected contacts.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs to use your location so that it may send it to your selected contacts.</string>

Checking for status using the following code reveals that the status is Not Determined.

if ([CLLocationManager locationServicesEnabled]) {
    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
        NSLog(@"RESTRICTED");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
        NSLog(@"DENIED");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
        NSLog(@"NOT DETERMINED");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
        NSLog(@"ALWAYS");
    } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
        NSLog(@"WHEN IN USE");
    }
}

EDIT: The viewController viewDidLoad method contains the following code:

- (void)viewDidLoad {
    [self.locationManager requestAlwaysAuthorization];
    [self.locationManager requestWhenInUseAuthorization];
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.delegate = self;

    if ([CLLocationManager locationServicesEnabled]) {
        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
            NSLog(@"RESTRICTED");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
            NSLog(@"DENIED");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
            NSLog(@"NOT DETERMINED");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
            NSLog(@"ALWAYS");
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
            NSLog(@"WHEN IN USE");
        }
    }
}

You need to use [yourLocationManager startUpdatingLocation] which will prompt the alert for Using location.

Until then authorizationStatus will be kCLAuthorizationStatusNotDetermined

Edit

self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
[self.locationManager requestAlwaysAuthorization]; 
self.locationManager.delegate = self;

Add this

You need to check authorization status, and if it's xxx, you need to call requestAlwaysAuthorization() or requestWhenInUseAuthorization() . That will trigger an alert to the user.

If you've deleted the app by long-pressing the app icon and tapping the X, that revokes the user's permission to use location services, so the app will be denied access until you call requestAlwaysAuthorization() or requestWhenInUseAuthorization() again.

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