if (nil == self.locationManager) {
self.locationManager = [[CLLocationManager alloc] init];
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[self.locationManager requestWhenInUseAuthorization];
}
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = 10000.0f;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];//GPS定位
[self.locationManager startUpdatingHeading];//检测设备的角度
在info.plist文件加一个string属性NSLocationWhenInUseUsageDescription,描述申请权限时的提示语