locationServicesEnabledクラス メソッドは、位置情報サービスのグローバル設定のみをテストします。私の知る限り、アプリが明示的に拒否されているかどうかをテストする方法はありません。ロケーション要求が失敗するのを待ち、CLLocationManagerDelegate メソッドのlocationManager:didFailWithError:を使用して、必要なことを行う必要があります。例えば:
- (void)locationManager: (CLLocationManager *)manager
didFailWithError: (NSError *)error {
NSString *errorString;
[manager stopUpdatingLocation];
NSLog(@"Error: %@",[error localizedDescription]);
switch([error code]) {
case kCLErrorDenied:
//Access denied by user
errorString = @"Access to Location Services denied by user";
//Do something...
break;
case kCLErrorLocationUnknown:
//Probably temporary...
errorString = @"Location data unavailable";
//Do something else...
break;
default:
errorString = @"An unknown error has occurred";
break;
}
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
その他のオプションについては、 CLLocationManager クラス リファレンスの CLError 定数に関するドキュメントを参照してください。