标签:ios8开发 地图定位 requestalwaysauthorization
因为在IOS8 的定位里新增了两个方法:
- (void)requestWhenInUseAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
- (void)requestAlwaysAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
如果需要仅在前台定位,你在调用startUpdatingLocation 前需要调用requestWhenInUseAuthorization
如果需要在前后台定位,你在调用startUpdatingLocation 前需要调用requestAlwaysAuthorization
同时在plist文件中添加NSLocationWhenInUseUsageDescription或NSLocationAlwaysUsageDescription字段
这两个字段的值应该设置为YES
代码参考入下:
-(void) initLocation {
self.locationManager=[[CLLocationManager alloc] init];
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
if(IsIOS8Later){
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
}本文出自 “ios开发庄园” 博客,请务必保留此出处http://macho.blog.51cto.com/8652974/1557376
标签:ios8开发 地图定位 requestalwaysauthorization
原文地址:http://macho.blog.51cto.com/8652974/1557376