iphone - 如何检测我的应用程序的位置服务禁用情况?

标签 iphone core-location cllocationmanager

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/

相关文章:

ios - 图像和文本字段的 Xcode 约束?

iphone - iPhone 4 上的 UITableViewCell 随机消失 + 滚动性能问题

iphone - RevMob sdk 5.9.0 在导入 <RevMobAds/RevMobAds.h> 时出现头文件错误

iphone - 如何在用户到达某个位置时触发视频?

iphone - 应用程序在后台或暂停时的位置更新

ios - 哪个委托(delegate)方法在单击时触发 CLLocationManager 不允许

iphone - CLLocationManager:没有网络,存储坐标并在网络可用时重新发送?

iphone - Skybox OpenGL ES iPhone和iPad

ios - iPhone : locationManagerShouldDisplayHeadingCalibration ignored/does nothing

ios - 用户授权位置使用时的双重 segue 行为