2013-03-25 82 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.)"