我正在开发一个 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/