因为在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]; }
时间: 2024-10-06 02:53:52