Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check for locationServicesEnabled always returns YES, Irrespective of 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 is always YES, independent of whether or not location services are enabled. Can any body help?

like image 596
alekhine Avatar asked Sep 02 '11 08:09

alekhine


1 Answers

instead of

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

try

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

I found this on the link.

Detecting whether location services are enabled for my app

like image 76
alekhine Avatar answered Nov 09 '22 00:11

alekhine