zoukankan      html  css  js  c++  java
  • iOS8无法开启定位问题

    升级iOS8了,突然发现定位服务无法开启。

     

    于是乎网上找答案。

    中文答案网上搜索一大圈,tmd都以讹传讹的用这个字段:NSLocationWhenInUseDescription
    终于在stackoverflow找到答案:http://stackoverflow.com/questions/24850128/ios-8-requestwheninuseauthorization-no-popup
    真正可用的字段是:NSLocationWhenInUseUsageDescription
    

     

    以下是iOS8开启定位的具体方法:

    1. 在Plist中追加下面两个字段 NSLocationWhenInUseUsageDescription, NSLocationAlwaysUsageDescription

    2. 在定位前初始化一个CLLocationManager(ARC下不能为临时变量,不然不会弹出请求定位的弹窗),并设置好代理。

    3.然后实现代理:

    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
        switch (status) {
            case kCLAuthorizationStatusDenied :
            {
                // 提示用户出错原因,可按住Option键点击 KCLErrorDenied的查看更多出错信息,可打印error.code值查找原因所在
                UIAlertView *tempA = [[UIAlertView alloc]initWithTitle:@"提醒" message:@"请在设置-隐私-定位服务中开启定位功能!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                [tempA show];
            }
                break;
            case kCLAuthorizationStatusNotDetermined :
    //根据自己的需求和plist中的字段调用requestWhenInUseAuthorization或requestAlwaysAuthorization
                if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
                    [_locationManager requestWhenInUseAuthorization];
                }
                break;
            case kCLAuthorizationStatusRestricted:
            {
                // 提示用户出错原因,可按住Option键点击 kCLErrorDenied的查看更多出错信息,可打印error.code值查找原因所在
                UIAlertView *tempA = [[UIAlertView alloc]initWithTitle:@"提醒"
                                                               message:@"定位服务无法使用!"
                                                              delegate:nil
                                                     cancelButtonTitle:@"确定"
                                                     otherButtonTitles:nil, nil];
                [tempA show];
            }
                break;
                
            default:
                break;
        }
    }
    View Code
  • 相关阅读:
    watch监听不到data数据
    滑块验证码 纯js
    position: fixed居中
    Vue插件之缺口滑块验证码 适合于手机和pc(插件vuemonoplastyslideverify)
    Vue之滑动验证码 适合于手机和pc JcRange(可分辨系统)
    Bus
    Table表中添加下拉框
    容器docker网络解析
    jstack定位java程序CPU使用高问题
    <摘>C#,MFC,Win32——实现系统级热键
  • 原文地址:https://www.cnblogs.com/bunsman/p/3988653.html
Copyright © 2011-2022 走看看