Check for locationServicesEnabled always returns YES, regardless of the manual toggle switch, to decide if location services are enabled

location = [[CLLocationManager alloc] init]; location.desiredAccuracy = kCLLocationAccuracyBestForNavigation ; location.distanceFilter = 10 ; location.delegate=self; locationEnabledBool = [CLLocationManager locationServicesEnabled]; if (locationEnabledBool ==NO) { UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" message:@"To re-enable, please go to Settings and turn on Location Service for this app." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [locationAlert show]; [locationAlert release]; } else [location startUpdatingLocation]; 

The value of locationEnabledBool always YES , regardless of whether location services are enabled. Can any organ help?

+7
source share
2 answers

instead

 if (locationEnabledBool == NO) { //give error message } 

try

 if ( [CLLocationManager locationServicesEnabled] ==NO || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { //give error message } 

I found this from the link.

Detecting if location services are enabled for my application

+11
source

When you test this code, you need to make sure that you tested it on the device, and not just using iOS Simulator.

In addition, I suggest that you double-check the settings on this device to make sure Location Services on the first settings page says Off .

0
source

All Articles