在iOS8以前,只要html
#import <CoreLocation/CoreLocation.h>引入CoreLocation.framework.ios
@property (nonatomic, strong) CLLocationManager *locationManager;
就可使用位置信息。atom
在iOS8以後,蘋果對定位進行了一些修改,其中包括定位受權的方法,CLLocationManager增長了下面的兩個方法:spa
(1)始終容許訪問位置信息code
- (void)requestAlwaysAuthorization;
htm
(2)使用應用程序期間容許訪問位置數據blog
- (void)requestWhenInUseAuthorization;
it
示例以下:io
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.htmlclass