在IOS8中定位功能新增了两个方法:
- (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表里面添加两条变量
在Info.plist中加入两个缺省没有的字段
-
NSLocationAlwaysUsageDescription
-
NSLocationWhenInUseUsageDescription
这两个字段没什么特别的意思,就是自定义提示用户授权使用地理定位功能时的提示语。
这样再写代码:
-(void)startLocation
{
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;
}
}