Iphone 检查locationServicesEnabled始终返回YES,无论手动切换开关是否用于确定是否启用位置服务

Iphone 检查locationServicesEnabled始终返回YES,无论手动切换开关是否用于确定是否启用位置服务,iphone,cllocationmanager,Iphone,Cllocationmanager,locationEnabledBool的值始终为YES,与是否启用位置服务无关。任何人都能帮上忙吗?测试此代码时,您需要确保在设备上测试,而不仅仅是使用iOS模拟器 此外,我建议您再次检查该设备上的设置,以确保位置服务在设置的第一页上显示关闭,而不是 location = [[CLLocationManager alloc] init]; location.desiredAccuracy = kCLLocationAccuracyBestForNavigation ; locat

locationEnabledBool
的值始终为
YES
,与是否启用位置服务无关。任何人都能帮上忙吗?

测试此代码时,您需要确保在设备上测试,而不仅仅是使用iOS模拟器

此外,我建议您再次检查该设备上的设置,以确保位置服务在设置的第一页上显示关闭,而不是

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];
试一试

我在链接上找到了这个


感谢您的回复。我在设备上运行代码,并检查定位服务是否在“设置”中关闭。而不是if(locationEnabledBool==NO)if(locationEnabledBool==NO | | |([CLLocationManager授权状态]==kCLAuthorizationStatusDenied))对我有效。
if([CLLocationManager locationServicesEnabled]==NO&[CLLocationManager授权状态]==kCLAuthorizationStatusDenied){//give error message}
在第一个[括号]中有一点输入错误,用&&代替||
if (locationEnabledBool == NO) {
    //give error message
}
if ( [CLLocationManager locationServicesEnabled] ==NO || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
    //give error message
}