IOS开发IOS 8simulator运行时,定位卡死bug解决
来源:互联网 发布:淘宝怎么解封永久封号 编辑:程序博客网 时间:2024/05/19 03:24
在 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的前面加上一句
//*****iOS8添加(2015/04/02)*****//if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {<span style="white-space:pre"></span>[_locationManager requestWhenInUseAuthorization];//iOS 8才有,且必须用上}/*if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {<span style="white-space:pre"></span>[_locationManager requestWhenInUseAuthorization];}if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {<span style="white-space:pre"></span>[_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
{
// 顯示警告
}
0 0
- IOS开发IOS 8simulator运行时,定位卡死bug解决
- IOS开发—App 在 IOS 8 的simulator运行时,定位卡死bug解决
- 系列:iOS开发-如何快速定位bug并解决
- iOS开发之解决APP界面卡死Bug,一级页面进行系统右滑返回,导致整个app卡死
- iOS开发 ☞ Simulator(模拟器)
- iOS开发 HomeKit Accessory Simulator
- iOS crash bug 定位
- ios 定位线上bug
- iOS 定位一闪而过bug
- 一个iOS 11BUG的发现、定位和解决
- 一个iOS 11BUG的发现、定位和解决
- 一个iOS 11BUG的发现、定位和解决
- 一个iOS 11BUG的发现、定位和解决
- 解决iOS 9 symbolicatecrash卡死
- 【iOS开发-47】如何下载iOS 7.1 Simulator 以及iOS 8离线的Documentation这些文件?
- iOS开发技巧-模拟器simulator添加图片
- ios开发simulator适配的尺寸
- ios编译运行提示:unable to boot ios simulator
- POJ 2570
- Kali-linux下安装安卓模拟器:Genymotion
- apache占用内存高解决办法
- CSS精心整理的面试题
- 省赛选拔赛——个人赛第二场
- IOS开发IOS 8simulator运行时,定位卡死bug解决
- jms 连接
- UVA12510 Collecting Coins
- 【HTML】Canvas(4)-进阶
- Linux软连接和硬链接
- get和post的区别与联系
- java API中提供的HashMap的常用方法
- jquery ajax servlet
- hibernate 4.O 注解 one-to-one 异常