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

  • 相关阅读:
    Java-列出所有系统属性
    Java-一个数组中的元素复制到另一个数组
    Java-将字符串转为数字
    Java单例模式简单实现
    Spring注解@Component、@Repository、@Service、@Controller
    VisualGDB系列2:VisualGDB对Linux平台的支持特性
    VisualGDB系列1:VisualGDB总体概述
    Docker入门(七):部署app
    Docker入门(六):Stacks
    Docker入门(五):Swarms
  • 原文地址:https://www.cnblogs.com/itlover2013/p/4143204.html
Copyright © 2011-2022 走看看