在iOS8之前,只要
#import <CoreLocation/CoreLocation.h>引入CoreLocation.framework.
@PRoperty (nonatomic, strong) CLLocationManager *locationManager;
就可以使用位置信息。
在iOS8之后,苹果对定位进行了一些修改,其中包括定位授权的方法,CLLocationManager增加了下面的两个方法:
(1)始终允许访问位置信息
- (void)requestAlwaysAuthorization;
(2)使用应用程序期间允许访问位置数据
- (void)requestWhenInUseAuthorization;
示例如下:
self.locationManager = [[CLLocationManager alloc]init];_locationManager.delegate = self;_locationManager.desiredAccuracy = kCLLocationAccuracyBest;_locationManager.distanceFilter = 10;[_locationManager requestAlwaysAuthorization];//添加这句[_locationManager startUpdatingLocation];
转载自:http://blog.devzeng.com/blog/ios8-corelocation-framework.html
新闻热点
疑难解答