- (void)requestWhenInUseAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
- (void)requestAlwaysAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
这两个新增的方法导致之前写的程序,在iOS8运行会出现定位功能无法正常使用!
正确让ios8定位的方法来了:
1.在Info.plist表里面添加两个变量
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
(这两个字段没什么特别的意思,就是自定义提示用户授权使用地理定位功能时的提示语)
![](https://i-blog.csdnimg.cn/blog_migrate/4de911ea12d6ad87ab84b94f9139404d.jpeg)
这里需要注意的是:很多小朋友加字段以后不记得吧value写为 “YES”,不写YES也是不行的喔~
2.添加代码:
CLLocationManager *locationManager = [[CLLocationManager alloc]init]; locationManager.delegate = self;
[locationManager requestAlwaysAuthorization];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
调用代理:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusNotDetermined:
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [locationManager requestWhenInUseAuthorization];
}
break;
default:
break;
}
}
3.这样就可以打开地图定位功能了!