iOS 腾讯云IM UIKit 升级XCode11后, 调用语音(取消) 崩溃问题

 腾讯云  IM UIKit , xcode10  升级XCode11  后调用 语音 功能奔溃:

 

进入 #import "TUIInputBar.m" 文件 

修改如下

- (void)recordBtnDown:(UIButton *)sender
{
    AVAudioSessionRecordPermission permission = AVAudioSession.sharedInstance.recordPermission;
    //在此添加新的判定 undetermined,否则新安装后的第一次询问会出错。新安装后的第一次询问为 undetermined,而非 denied。
    if (permission == AVAudioSessionRecordPermissionDenied || permission == AVAudioSessionRecordPermissionUndetermined) {
        [AVAudioSession.sharedInstance requestRecordPermission:^(BOOL granted) {
            //点击取消后重新进入会造成崩溃,原因是:第二次已经不在主线程了
            /** 
             * dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)
             *该方法不仅能够判断当前是否是主线程。
             *还可用来很好的判断当前是否是在主队列。
             */
                        
            if (!granted) {
                if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
                           
                    [self showAlertView];
                } else {
                    dispatch_sync(dispatch_get_main_queue(), ^{
                        [self showAlertView];
                    });
                };
              
          }
        }];
        return;
    }
    //在此包一层判断,添加一层保护措施。
    if(permission == AVAudioSessionRecordPermissionGranted){
        if(!_record){
            _record = [[TUIRecordView alloc] init];
            _record.frame = [UIScreen mainScreen].bounds;
        }
        [self.window addSubview:_record];
        _recordStartTime = [NSDate date];
        [_record setStatus:Record_Status_Recording];
        [_recordButton setTitle:@"松开 发送" forState:UIControlStateNormal];
        [self startRecord];
    }
}
-(void)showAlertView{
    
     UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"无法访问麦克风" message:@"开启麦克风权限才能发送语音消息" preferredStyle:UIAlertControllerStyleAlert];
      [ac addAction:[UIAlertAction actionWithTitle:@"以后再说" style:UIAlertActionStyleCancel handler:nil]];
      [ac addAction:[UIAlertAction actionWithTitle:@"去开启" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
          UIApplication *app = [UIApplication sharedApplication];
          NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
          if ([app canOpenURL:settingsURL]) {
              [app openURL:settingsURL];
          }
      }]];
     [self.mm_viewController presentViewController:ac animated:YES completion:nil];
    
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

app开发工程师V帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值