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];後臺

相關文章
相關標籤/搜索