IOS4 最近引入了为特定应用程序启用/禁用位置服务的功能。
我需要检测我的应用程序是否启用/禁用了此设置。
首先我尝试过:
if ([CLLocationManager locationServicesEnabled])
{
....
}
但是,这指的是全局定位服务,而不是特定的应用程序设置。
第二我尝试过使用
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
...
}
它可以工作,但在服务应用程序设置被禁用的情况下以及其他情况下(例如,如果某项措施因某些原因失败),它都会被调用。
我需要一个代码来检测我的应用程序是否允许使用位置服务。
我怎样才能实现这一目标?
感谢您的支持
最佳答案
来自 locationManager: didFailWithError: 的文档
If the user denies your application’s use of the location service, this method reports a kCLErrorDenied error. Upon receiving such an error, you should stop the location service.
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
if ([[error domain] isEqualToString: kCLErrorDomain] && [error code] == kCLErrorDenied) {
// The user denied your app access to location information.
}
}
您可以找到其他错误代码 here .
关于iphone - 如何检测我的应用程序的位置服务禁用情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3831034/