小伙伴们更新了iOS8系统后,发现有的程序无法定位了,那是因为iOS8对定位隐私做了优化,需要添加一些配置,具体操作如下所示:
1. @interface里:
CLLocationManager *locationManager;2. 初始化:
locationManager = [[CLLocationManager alloc] init];3. 调用请求:
[locationManager requestAlwaysAuthorization];[locationManager startUpdatingLocation];
4. 在 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];