热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

检查是否接受NSLocationWhenInUseUsageDescription

如何解决《检查是否接受NSLocationWhenInUseUsageDescription》经验,为你挑选了1个好方法。

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

谢谢.



1> Glen T..:

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

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... 
}

目标C示例:

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

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


推荐阅读
author-avatar
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有