zoukankan      html  css  js  c++  java
  • 系统定位在iOS8中的改变

    CLLocationManager这个系统定位的类在iOS8之前要实现定位,只需要遵守CLLocationManagerDelegate这个代理即可:

    - (void)startLocate

    {  

         if([CLLocationManager locationServicesEnabled]){

            _locManager = [[CLLocationManager alloc]init];

             [self.locManager setDelegate:self];

            [self.locManager setDesiredAccuracy:kCLLocationAccuracyBest];

            [self.locManager startUpdatingLocation];

        }

    }

    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

    {

      [_locManager stopUpdatingLocation];

        CLLocation *currentLocation = [locations lastObject];

        CLLocationCoordinate2D coor = currentLocation.coordinate;

        NSString *latitude =  @(coor.latitude).description;

        NSString *longitude = @(coor.longitude).description;

    }

    iOS8之前以上两个方法正常的情况下,已经能够正常获取经纬度了。但是在iOS8下,则需要在startLocate这个方法中在CLLocationManager这个类实例化后添加如下代码:

            if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

            {

                [ self.locManager requestAlwaysAuthorization];

            }

    但是仅仅添加以上代码还不行,还需要在工程的info.plist文件中添加键值对:

                      Key                                                                        Type                                                      Value

    NSLocationAlwaysUsageDescription              Array/Dictionary/Boolean/Data/Date/Number/String              

    注意上方对应的Type,这七种类型都支持,我重点说说String和Boolean类型:

    1.Type为String时:Value这个地方开发者可以根据需要说明定位的具体目的,让用户清楚的知道开启定位后用于做什么,更加透明化,清晰化;

    弹框中"定位"两字即为Type为String时Value设置的值为"定位"时的展示。

    当Value的值为空时,弹框显示如下:

    2.Type为Boolean时:Value填YES即可。弹框显示如下:

    而iOS8以前,定位提示的弹框显示如下:

     在iOS8下如果不做以上两处的处理,系统CLLocationManager这个类即时指定了代理,其获取经纬度的代理方法也不会走。

  • 相关阅读:
    Windows 8的语音识别
    硬件驱动程序的知识点滴
    怎么将一张100KB以上大小的电子图片压缩成30KB以内
    Hadoop概念学习系列之Hadoop新手学习指导之入门需知(二十)
    Hadoop概念学习系列之Hadoop、Spark学习路线(很值得推荐)(十八)
    研究生,别再玩了,你玩不起!
    redis源代码解读之内存管理————zmalloc文件
    线段树之入门篇
    C#托付和事件
    dlmalloc 2.8.6 源代码具体解释(6)
  • 原文地址:https://www.cnblogs.com/JoelZeng/p/4090741.html
Copyright © 2011-2022 走看看