本帖最后由 chenjie_1986 于 2014-10-16 09:43 编辑
升级iOS 8后,将无法定位,特给出解决方案。
1.在Plist中追加下字段NSLocationWhenInUseUsageDescription或NSLocationAlwaysUsageDescription(这两个字段必须有其中一个,内容是系统alert的文言,文言可为空) ,如下图所示:
WhenInUse是应用在前台的时候可以搜到更新的位置信息,Always是除了应用在前台,应用在后台(suspend或terminated)都可以获取到更新的位置数据 ,根据需要,按需去申请权限。
2.修改代码,在self.mapView.showsUserLocation= YES;前加入如下代码
定义CLLocationManager对象,私有的或者property都可以,以确保alert弹出,用户点击完以后 CLLocationManager 对象还没被释放。示例如下:- @implementation ViewController
- {
- CLLocationManager * locationManager;
- }
- ……
- locationManager =[[CLLocationManager alloc] init];
- // fix ios8 location issue
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
- #ifdef __IPHONE_8_0
- if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
- {
- [locationManager performSelector:@selector(requestAlwaysAuthorization)];//用这个方法,plist中需要NSLocationAlwaysUsageDescription
- }
-
- if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
- {
- [locationManager performSelector:@selector(requestWhenInUseAuthorization)];//用这个方法,plist里要加字段NSLocationWhenInUseUsageDescription
- }
- #endif
- }
复制代码
以上解决方案仅针对Xcode6,适用于V2.3.0(含)之前版本。
|