標籤:
iOS 8定位補充
iOS 8定位需要修改2個地方
1.info.plist檔案中添加NSLocationAlwaysUsageDescription:描述資訊
從iOS 8開始,使用者定位分兩種情況總是使用使用者位置:NSLocationAlwaysUsageDescription使用應用時定位:NSLocationWhenInUseDescription
2.在CLLocationManager中調用
- (void)requestAlwaysAuthorization
- (void)requestWhenInUseAuthorization
#import "ViewController.h"#import <CoreLocation/CoreLocation.h>@interface ViewController () <CLLocationManagerDelegate>@property(nonatomic,strong)CLLocationManager *mgr;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; [self.mgr startUpdatingLocation]; // 如果是iOS8,需要請求授權方式(進行判斷,否則在iOS7會崩潰,需要先在info.plist中配置) // 1.通過判斷系統判斷來確定是否需要請求requestAlwaysAuthorization授權// if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {// [self.mgr requestAlwaysAuthorization];// } // 2.通過判斷是否有該方法來判斷是否需要請求requestAlwaysAuthorization授權 if ([self.mgr respondsToSelector:@selector(requestAlwaysAuthorization)]) { [self.mgr requestAlwaysAuthorization]; }}- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ NSLog(@"擷取到使用者的位置");}- (CLLocationManager *)mgr{ if (_mgr == nil) { _mgr = [[CLLocationManager alloc] init]; _mgr.delegate = self; } return _mgr;}@end
iOS8 定位補充