IOS开发—App 在 IOS 8 的simulator运行时,定位卡死bug解决
2016-03-08 00:00
716 查看
摘要: 在IOS 8 的simulator中运行app,就会卡死在定位的页面。原因是在 iOS 7 以及更早之前的版本,MapView 显示使用者位置不需作到 CLLocationManager,现在都要了。
在 iOS 8 上编译会出现以下 log :
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
经搜索得到解决方法如下:
1、修改info.plist:
新增key值为NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription(这里,我将两个都加了进去),value可以为空,也可以设置YES,不过我得问题还是不能解决,最终还是找到得了问题所在,就是info.plist中还需要包含Supported interface orientations 这个Array字段。然后运行就解决了。
2、修改代码:
在调用方法startUpdatingLocation的前面加上一句
?
3、博客原文修改方法:
?
?
上面那行是 iOS 8 以上,第二行是 iOS 7 以下,因為 kCLAuthorizationStatusAuthorized 在 iOS 8 完全不能使用。
?
在 iOS 8 上编译会出现以下 log :
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
经搜索得到解决方法如下:
1、修改info.plist:
新增key值为NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription(这里,我将两个都加了进去),value可以为空,也可以设置YES,不过我得问题还是不能解决,最终还是找到得了问题所在,就是info.plist中还需要包含Supported interface orientations 这个Array字段。然后运行就解决了。
2、修改代码:
在调用方法startUpdatingLocation的前面加上一句
?
1 2 3 | if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [locationManager requestWhenInUseAuthorization]; } |
?
1 2 3 4 5 6 7 | locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy=kCLLocationAccuracyBest; if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [locationManager requestWhenInUseAuthorization]; } [locationManager startUpdatingLocation]; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | - ( void )locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { if ( ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorizedWhenInUse) || (![locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorized) ) { NSString *message = @ "您的手機目前並未開啟定位服務,如欲開啟定位服務,請至設定->隱私->定位服務,開啟本程式的定位服務功能" ; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@ "無法定位" message:message delegate:nil cancelButtonTitle:@ "確定" otherButtonTitles: nil]; [alertView show]; } else { [locationManager startUpdatingLocation]; } } |
?
1 2 3 4 5 6 7 8 9 10 | CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorized) { // 开始定位 } else { // 预示警告 } |
相关文章推荐
- App云端打包失败常见问题汇总
- KeyMob移动广告聚合平台嵌入几百款APP日展现次数过万
- IOS博客项目搭建-08-项目使用本地Git
- 支付宝移动支付之IOSApp调用支付宝钱包
- android之调用webservice 实现图片上传
- web项目转android项目方法主要使用webview
- Android+Axis2
- Android新建项目,或者导入项目出现R文件丢失,解决方案 .
- ios SDWebImage 图片缓存运用
- runtime 运行时机制 完全解读
- Android 解压文件包
- Android SD卡
- Android 那些坑
- 今天开通博客,记录一下IOS学习历程
- android_activity隐式意图跳转到浏览器和短信的界面
- iSensor APP 之 摄像头调试 OV5642 续集2
- Unity3D 参考网址
- cocos2dx TMX地图
- 浅谈Android中的Handler
- 如何在SVN创建自己的项目