zoukankan      html  css  js  c++  java
  • iOS~判断应用是否有定位权限

    在特定场景下我们需要判断用户是否允许应用获取定位权限


    1.导入类库:
    #import <CoreLocation/CLLocationManager.h>
    2.判断用户手机是否开启了定位服务:
    这里就要查看CLLocationManager的授权状态,此方法会返回当前授权状态:
    [CLLocationManager authorizationStatus]
    
    授权状态为枚举值:
    kCLAuthorizationStatusNotDetermined                  //用户尚未对该应用程序作出选择
    kCLAuthorizationStatusRestricted                     //应用程序的定位权限被限制 
    kCLAuthorizationStatusAuthorizedAlways               //一直允许获取定位
    kCLAuthorizationStatusAuthorizedWhenInUse            //在使用时允许获取定位
    kCLAuthorizationStatusAuthorized                     //已废弃,相当于一直允许获取定位
    kCLAuthorizationStatusDenied                         //拒绝获取定位
    3.判断用户是否授权应用获取定位权限的完整代码:
    if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {        
    
    //定位功能可用
    
    }else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
    
    //定位不能用
    
    }

    有不足之处还望补充。

  • 相关阅读:
    成为明星程序员的10个提示
    使用命令时一些快捷的方法
    mysql字符串截取
    MFGTool2批量操作
    busybox microcom Segmentation fault
    Linux 定制X86平台操作系统
    Buildroot MariaDB替代MySQL
    arcotg_udc: exports duplicate symbol imx_usb_create_charger (owned by kernel)
    create newline in Github Bio
    BusyBox ifup udhcpc后台运行
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/7112328.html
Copyright © 2011-2022 走看看