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];
locationEnabledBool
的值始终为YES
,与是否启用位置服务无关。任何人都可以帮忙吗?
答案 0 :(得分:11)
而不是
if (locationEnabledBool == NO) {
//give error message
}
尝试
if ( [CLLocationManager locationServicesEnabled] ==NO || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
//give error message
}
我在链接上找到了这个。
答案 1 :(得分:0)
在测试此代码时,您需要确保在设备上进行测试,而不仅仅是使用iOS模拟器。
此外,我建议您仔细检查该设备上的设置,以确保设置的第一页上的位置服务显示关闭。< / p>