Chris Chris - 9 days ago 6
iOS Question

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");
}
}
}

Answer

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