检查locationServicesEnabled始终返回YES,无论手动切换开关如何,都要确定是否启用了位置服务

ale*_*ine 7 iphone cllocationmanager

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];
Run Code Online (Sandbox Code Playgroud)

locationEnabledBool始终是值YES,与是否启用位置服务无关.任何身体都能帮忙吗?

ale*_*ine 11

代替

if (locationEnabledBool == NO) {
    //give error message
}
Run Code Online (Sandbox Code Playgroud)

尝试

if ( [CLLocationManager locationServicesEnabled] ==NO || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
    //give error message
}
Run Code Online (Sandbox Code Playgroud)

我在链接上找到了这个.

检测是否为我的应用启用了位置服务