iOS 8 : Location Services not working(iOS 8 定位失败)

若是是xcode6和ios 8的话,须要调用 CLLocationManager requestAlwaysAuthorization 方法,具体步骤以下:ios

1. @interface里:
   CLLocationManager *locationManager;
2. 初始化:
   locationManager = [[CLLocationManager alloc] init];
3. 调用请求:
   [locationManager requestAlwaysAuthorization];
   [locationManager startUpdatingLocation];
4. 在 info.plist里加入:
   NSLocationWhenInUseDescription,容许在前台获取GPS的描述
   NSLocationAlwaysUsageDescription,容许在后台获取GPS的描述xcode

5. 后台长时间定位必须设置:code

    locationManager.pausesLocationUpdatesAutomatically = NO;ip

ps:调用请求前加上ios版本判断就完美了。it

完美一下:io

// 判斷是否 iOS 8
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
  [self.locationManager requestAlwaysAuthorization]; // 永久受权
  [self.locationManager requestWhenInUseAuthorization]; //使用中受权
}
[self.locationManager startUpdatingLocation];后台

相关文章
相关标签/搜索