Core Location Manager在IOS8中的改变
2014-10-24 10:09
253 查看
以前的代码在ios7里运行得好好的,到ios8就不行了,没有报错没有警告,只在运行时有log显示 Trying to start MapKit location updates without prompting for location authorization. Must
call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
解决方法分两步:
首先, 在Info.plist文件里添加NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription ,根据你的需要,添加两者或其中的一个.这两个key都是String类型的,value可以为空.
接下来,就要在你的代码里加上 requestWhenInUseAuthorization 和 requestAlwaysAuthorization方法(两者或其一).代码如下:
到这里,问题应该解决了,运行程序试试看.
但如果你是使用的MKMapView,接着往下看:
如果使用MapView的showsUserLocation属性来定位,除了在info.plist里添加key之外,还需要在ViewController里加上一个CLLocationManager的属性,然后在showsUserLocation之前,加上上面的代码,问题就解决了!代码如下:
call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
解决方法分两步:
首先, 在Info.plist文件里添加NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription ,根据你的需要,添加两者或其中的一个.这两个key都是String类型的,value可以为空.
接下来,就要在你的代码里加上 requestWhenInUseAuthorization 和 requestAlwaysAuthorization方法(两者或其一).代码如下:
self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // 检查是否为ios8,直接调用在7下面会蹦掉 if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; } [self.locationManager startUpdatingLocation];
到这里,问题应该解决了,运行程序试试看.
但如果你是使用的MKMapView,接着往下看:
如果使用MapView的showsUserLocation属性来定位,除了在info.plist里添加key之外,还需要在ViewController里加上一个CLLocationManager的属性,然后在showsUserLocation之前,加上上面的代码,问题就解决了!代码如下:
self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // Check for iOS 8 if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [self.locationManager requestAlwaysAuthorization]; } self.mapView.showsUserLocation = YES;
相关文章推荐
- Core Location Manager在iOS8中的改变
- iOS8 CLLocationManager 的改变导致 locationManager didUpdateLocations不能被调用的解决办法
- Core Location Manager Changes in iOS 8(iOS8获取不到地理位置)
- iOS CoreLocation框架第二章—— CLLocationManagerDelegate全解
- 迎接iOS8 - CoreLocation的变化
- iOS8下,CoreLocation的变化
- iOS8 - CoreLocation的变化
- iOS CoreLocation使用(iOS8 回调不行的问题解决)
- Core Location Manager Changes in iOS 8 英文文档
- iOS CoreLocation框架第一章—— CLLocationManager的使用(包含iOS6,iOS8,iOS9各种变动)
- CoreLocation Authorization in iOS8+
- Core Location Manager Changes in iOS 8
- ios8下LocationManager及Nsnotification使用
- 【iOS开发-109】CoreLocation框架的两个主要类CLLocationManager和CLGeoCoder介绍
- iOS8 Core Location (授权。。。室内定位。。。访问监控。。。)
- iOS8之后CoreLocation定位的使用
- 迎接iOS8 - CoreLocation的变化
- ios8 - CoreLocation定位服务的变化
- Core Location Manager Changes in iOS 8
- 简单强大的选择状态管理器,批量改变View样式 SelectStateManager - android