iOS 8 地图授权

来源:互联网 发布:健步走计步器软件 编辑:程序博客网 时间:2024/05/21 10:51


iOS8 中使用地图是出现以下错误:

[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthoriz 


解决方式:

1:在 info.plist文件中添加

  (1)NSLocationAlwaysUsageDescription

  (2)NSLocationWhenInUseUsageDescription

这两个键的值就是授权alert的描述,也可以不填,


2:在.m文件内加上如下代码申请授权

 if ([CLLocationManager locationServicesEnabled]) {

  self.locationManager = [[CLLocationManager alloc] init];

 _locationManager.delegate = self;

 _locationManager.desiredAccuracy = kCLLocationAccuracyBest; //控制定位精度,越高耗电量越大。

 _locationManager.distanceFilter = 100; //控制定位服务更新频率。单位是

  [_locationManager startUpdatingLocation];


  //ios 8.0下要授权

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)


  [_locattionManager  requestAlwaysAuthorization];

 [_locationManager requestWhenInUseAuthorization];   //调用了这两句,就会弹出允许框了.

 }


0 0
原创粉丝点击