企业信息

    北京沃赢科技有限公司

  • 12
  • 公司认证: 营业执照已认证
  • 企业性质:
    成立时间:
  • 公司地址: 北京市 海淀区 海淀街道 北京市海淀区银海大厦
  • 姓名: 刘老师
  • 认证: 手机未认证 身份证未认证 微信未绑定

    IOS开发—定位卡死bug解决

  • 所属行业:商务服务 教育培训 管理培训
  • 发布日期:2015-08-11
  • 阅读量:313
  • 价格:面议
  • 产品规格:不限
  • 产品数量:10000.00 件
  • 包装说明:不限
  • 发货地址:北京海淀海淀  
  • 关键词:在线教育,我赢职场,IOS

    IOS开发—定位卡死bug解决详细内容

    IOS开发—App 在 IOS 8 的simulator运行时,定位卡死bug解决
    在 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];
    }
    3、博客原文修改方法:
    ?
    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];
    ????}
    }
    上面那行是 iOS 8 以上,*二行是 iOS 7 以下,因为 kCLAuthorizationStatusAuthorized 在 iOS 8 完全不能使用。
    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10	CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    ?????
    ????if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorized) {
    ?
    ????// 开始定位
    ?
    }else {
    ?
    ????// 显示警告
    }
    学习链接/ios/?tg=5009295340
    学习交流群:317140762
    
    
    

    http://jiexiaotan.cn.b2b168.com
    欢迎来到北京沃赢科技有限公司网站, 具体地址是北京市海淀区海淀街道北京市海淀区银海大厦,联系人是刘老师。 主要经营iOS开发、互联网架构师、安卓、Oracle、SAP、RedHat等。 单位注册资金未知。 我们公司主要服务有:教育教学软件等,我们愿以优质的服务和诚意、为您提供精良的产品和专业枝术,共创美好未来!