2013-03-25 81 views
0

我是检查GPS位置on/off使用此代码GPS位置是开/关在iphone我的应用程序

BOOL servicesEnabled = [CLLocationManager locationServicesEnabled]; 

它正常工作时,对iphone /关LocationServices,但我掀起LocationServices为我的应用程序也只返回servicesEnabledYES,到时候[CLLocationManager locationServicesEnabled]如何检查locationServicesEnabled在我的应用程序 例:我是禁用等作为Instagram的,如何解决这个问题,检查LocationServices特别是应用在iPhone或iPad上我的应用程序的位置服务? enter image description here

回答

2

使用您的CLLocationManagerDelegate's locationManager: didFailWithError:方法并检查kCLErrorDenied错误以查看用户是否拒绝了位置服务。

- (void)viewDidLoad 
{ 
    locationManager = [[CLLocationManager alloc] init]; 

    locationManager.delegate = self; 

    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; 

    // Set a movement threshold for new events. 

    locationManager.distanceFilter = 500; 

    [locationManager startUpdatingLocation]; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)locationManager:(CLLocationManager *)manager 

    didUpdateLocations:(NSArray *)locations { 

    // If it's a relatively recent event, turn off updates to save power 

} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 

    NSLog(@"%@",error); 
} 

如果位置服务禁用您的应用程序,然后它给你错误

Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.)"