码迷,mamicode.com
首页 > 移动开发 > 详细

系统定位在iOS8中的改变

时间:2014-11-12 00:15:11      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   os   sp   文件   

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这个地方开发者可以根据需要说明定位的具体目的,让用户清楚的知道开启定位后用于做什么,更加透明化,清晰化;

bubuko.com,布布扣

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

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

bubuko.com,布布扣

 

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

bubuko.com,布布扣

 

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

bubuko.com,布布扣

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

系统定位在iOS8中的改变

标签:des   style   blog   http   io   ar   os   sp   文件   

原文地址:http://www.cnblogs.com/JoelZeng/p/4090741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!