ios - 检查 NSLocationWhenInUseUsageDescription 的接受情况

标签 ios ios8 ibeacon

我正在开发一个 iOS 应用程序,用于处理信标和位置管理。 在 iOS 8 中,应用程序必须在 plist 文件中包含“NSLocationWhenInUseUsageDescription”键,该键将在启动时显示在应用程序中,以获取用户启用位置跟踪的权限。 如何检测用户是否接受?我想就此做出决定。

谢谢。

最佳答案

您可以通过在类设置中实现以下方法作为 CLLocationManager 委托(delegate)来检测这一点(实现 CLLocationManagerDelegate 协议(protocol))

Swift 中的示例:

// MARK: CLLocationManagerDelegate

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    // check status to see if we’re authorized
    let authorized = (status == CLAuthorizationStatus.AuthorizedWhenInUse)
    // handle acceptance... 
}

objective-c 示例:

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

    BOOL isAuthorized = status == kCLAuthorizationStatusAuthorizedWhenInUse;
    // handle acceptance..        
}

关于ios - 检查 NSLocationWhenInUseUsageDescription 的接受情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28848761/

相关文章:

javascript - HTML5 视频无法在 iOS9 (iPad) 上启动

ios - 恒定速度,同时仍然能够施加脉冲

ios - 应用商店拒绝: ASIdentifierManager

iOS Swift - 像Skype一样的底部菜单

横向模式下的 iOS 8 状态栏背景方向

Android信标库——多区域监控

javascript - 设置输入字段的值不会影响 Safari 中的虚拟键盘

swift - CVCalendar 编译时错误

iBeacon:尝试跟踪比我们有空间更多的区域

ios - 带有 "When In Use"位置访问错误代码 4 的 CLLocationManager requestStateForRegion