腾讯云 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];
}