如果是xcode6和ios 8的话,需要调用 CLLocationManager requestAlwaysAuthorization 方法,具体步骤如下:

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

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

完美一下:

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

相关文章:

  • 2021-10-16
  • 2021-06-15
  • 2021-12-15
  • 2021-05-10
  • 2022-02-25
  • 2022-01-09
  • 2021-11-12
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2021-12-10
  • 2021-04-24
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案