I have a problem where the locationManager:didChangeAuthorizationStatus
is not being called after the user either (1) accepts or (2) declines my request to use location services. By placing out different NSLog
statements, I have reached the conclusion that the method is called when I request authorization, but not when the user makes a choice. Have anyone had the same issues? If so, how did you solve them?
Here's how I initialize my location manager
:
if (_locationManager == nil) {
NSLog(@"Creating location manager");
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.distanceFilter = kCLDistanceFilterNone;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
NSLog(@"Not determined");
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"dynamicNotifOn"]) {
[_locationManager requestAlwaysAuthorization];
} else {
[_locationManager requestWhenInUseAuthorization];
}
} else if (...) {...
and here's the method:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(@"Callback");
if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"Authorized");
[_mainButton setIsLoading:NO];
[self startGettingLocation];
} else if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted) {
NSLog(@"Denied");
_currentState = CurrentStateError;
[_mainButton setUpButtonForState:_currentState];
}
}
After I press the button that initializes the location manager (the top code-block), this is what the console prints out:
Creating location manager
Not determined
Callback
And then I make a choice in the AlertView that pops up:
*nothing*
In my case the problem was in non-main thread. Just make sure you creating location manager on the main thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With