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
  • 相关阅读:
    day35—JavaScript操作元素(创建、删除)
    day34—JavaScript实现DOM操作
    day33—前端开发的模块化和组件化
    day32—CSS多列布局学习
    day31—CSS Reset 与页面居中布局
    JVM(18)之 Class文件
    JVM(17)之 准备-解析-初始化
    JVM(16)之 双亲委派模型
    JVM(15)之 类加载器
    JVM(14)之 类加载机制
  • 原文地址:https://www.cnblogs.com/bunsman/p/3988653.html
Copyright © 2011-2022 走看看