• 系统定位在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这个类即时指定了代理,其获取经纬度的代理方法也不会走。

  • 相关阅读:
    DataNucleus Access Platform 3.2 M2 发布
    dnsjava 2.1.4 发布,Java 的 DNS 解析包
    deltasql 1.5.5 发布,数据库模型版本控制
    Mezzanine 1.3 和 Cartridge 0.7 发布!
    Spring Framework 3.2 GA版发布,Spring MVC焕然一新
    Filemonitor 2.2.0 发布,文件监控工具
    Rudiments 0.40 发布,C++ 常用工具包
    脚本编程语言 Felix
    JRuby 1.7.2 发布
    OfficeFloor 2.7.0 发布,IoC 框架
  • 原文地址:https://www.cnblogs.com/itlover2013/p/4143204.html
Copyright © 2020-2023  润新知