注册

[已解决] 发送语音消息会崩溃

之前打了全局断点, 但是不能显示在哪儿错了, 求救大侠们, 我已尽力了...
请问只是需要发送语音消息还需要使用 EaseMobSDK 吗? 我现在使用的是 EaseMobSDKLite, 但是发送语音消息会崩溃, 我重新运行模拟器后, 可以在聊天记录 tableview 上显示这个录音, 可以正常播放, 
 
这个是我对应的代码, 有劳大侠帮忙啊~~
这个是我对应的代码, 有劳大侠帮忙~~
#pragma mark ChatToolViewDelegate Method
//我把按下录音按钮, 松开, 取消 写成一个枚举了,用 switch 判断
-(void)ChatToolViewWithButtonType:(ChatToolViewVoiceButtonType)buttonType{
switch (buttonType) {
case ChatToolViewVoiceButtonStart:
{
//生成录音
NSDate *date = [NSDate date];
NSString *fileName = [NSString stringWithFormat:@"%d",(int)[date timeIntervalSince1970]];
[[EMCDDeviceManager sharedInstance] asyncStartRecordingWithFileName:fileName completion:^(NSError *error) {
if (!error) {
NSLog(@"录音开始");
}
}];
break;
}
case ChatToolViewVoiceButtonSend:
{
[[EMCDDeviceManager sharedInstance] asyncStopRecordingWithCompletion:^(NSString *recordPath, NSInteger aDuration, NSError *error) {
if (!error) {
NSLog(@"录音:%@, 时长:%zd",recordPath,aDuration);
}
//发送录音
[self sendVoiceWithFilePath:recordPath duration:aDuration];
}];
break;
}
case ChatToolViewVoiceButtonCancel:{
NSLog(@"取消录音");
break;
}
default:
break;
}
}

//发送录音消息的方法
-(void)sendVoiceWithFilePath:(NSString *)recordPath duration:(NSInteger)aDuration{
EMChatVoice *voice = [[EMChatVoice alloc] initWithFile:recordPath displayName:@"【语音】"];
voice.duration = aDuration;
EMVoiceMessageBody *voiceBody = [[EMVoiceMessageBody alloc] initWithChatObject:voice];
EMMessage *message = [[EMMessage alloc] initWithReceiver:self.buddy.username bodies:@[voiceBody]];
message.messageType = eMessageTypeChat;//单聊
[[EaseMob sharedInstance].chatManager
asyncSendMessage:message
progress:self
prepare:^(EMMessage *message, EMError *error)
{
if (!error) {
NSLog(@"语音消息即将发送成功");
}else{
NSLog(@"语音消息即将发送失败");
}

} onQueue:nil
completion:^(EMMessage *message, EMError *error)
{
if (!error)
{
NSLog(@"语音发送成功");
//在聊天数据数组里添加这条消息并更新
[self.chatRecordArray addObject:message];
[self.chatTableView reloadData];
//滚到最新一条消息
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.chatRecordArray.count - 1 inSection:0];
[self.chatTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}else{
NSLog(@"语音发送失败");
}
} onQueue:nil];
}


已邀请:
嘿嘿不好意思添麻烦了, 我自己解决了, 没有添加IEMChatProgressDelegate和实现-(void)setProgress:(float)progress forMessage:(EMMessage *)message forMessageBody:(id<IEMMessageBody>)messageBody; 
写上就好了~~~ 谢谢大家

要回复问题请先登录注册