小伙伴们更新了iOS8系统后,发现有的程序无法定位了,那是因为iOS8对定位隐私做了优化,需要添加一些配置,具体操作如下所示:
-
@interface里:
CLLocationManager *locationManager; -
初始化:
locationManager = [[CLLocationManager alloc] init]; -
调用请求:
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation]; -
在 info.plist里加入:
NSLocationWhenInUseUsageDescription ,允许在前台获取GPS的描述
NSLocationAlwaysUsageDescription ,允许在后台获取GPS的描述
//定位对象
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
网友评论