|
|
@@ -1984,28 +1984,45 @@ static const CGFloat kQuoteViewHeight = 46.0f;
|
|
|
NSLog(@"UpInside----------");
|
|
|
[_recorder stop];
|
|
|
_recorder=nil;
|
|
|
- NSURL *fileURL = [NSURL fileURLWithPath:_AudiofilePath];
|
|
|
+ NSURL *yuanfileURL = [NSURL fileURLWithPath:_AudiofilePath];
|
|
|
if(_rcdL<2){//语音太短
|
|
|
- [[NSFileManager defaultManager] removeItemAtURL:fileURL error:nil];
|
|
|
+ [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
|
|
|
[self.heatBeat invalidate];
|
|
|
self.heatBeat = nil;
|
|
|
[MBProgressHUD showWithText:@"語音太短"];
|
|
|
return;
|
|
|
}
|
|
|
+ NSLog(@"_AudiofilePath:%@",_AudiofilePath);
|
|
|
+ NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
|
|
|
+ NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:yuanfileURL.lastPathComponent]; // 目标文件路径
|
|
|
+
|
|
|
+ NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
+ NSError *error = nil;
|
|
|
+ BOOL success = [fileManager copyItemAtPath:_AudiofilePath toPath:destinationPath error:&error];
|
|
|
+ if (success) {
|
|
|
+ NSLog(@"文件成功复制到本地");
|
|
|
+ } else {
|
|
|
+ NSLog(@"文件复制失败: %@", error.localizedDescription);
|
|
|
+ }
|
|
|
+ NSLog(@"destinationPath:%@",destinationPath);
|
|
|
+
|
|
|
+
|
|
|
+ NSURL *fileURL = [NSURL fileURLWithPath:destinationPath];
|
|
|
|
|
|
ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileURL];
|
|
|
model.fileURL = fileURL;
|
|
|
- model.filePath = _AudiofilePath;
|
|
|
+ model.filePath = destinationPath;
|
|
|
NSString *strtime = [self getLocalTime];
|
|
|
//普通上传
|
|
|
+ [self sendYuyinMsg:model.fileURL.lastPathComponent filePth:destinationPath localtime:strtime state:0];
|
|
|
[OSSManager.sharedManager asyncPutFile:model.fileURL.lastPathComponent localFilePath:model.filePath thrid:strtime progress:^(NSInteger pcent, NSString * loacaltime) {
|
|
|
// [self Ossupdatajidu:loacaltime uploadProgress:pcent];
|
|
|
} success:^(id res, NSString * loacaltime) {
|
|
|
- [self sendYuyinMsg:model.fileURL.lastPathComponent localtime:loacaltime];
|
|
|
- [[NSFileManager defaultManager] removeItemAtURL:fileURL error:nil];
|
|
|
+ [self sendYuyinMsg:model.fileURL.lastPathComponent filePth:destinationPath localtime:loacaltime state:1];
|
|
|
+ [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
|
|
|
} failure:^(NSError * error, NSString * loacaltime) {
|
|
|
-
|
|
|
- [[NSFileManager defaultManager] removeItemAtURL:fileURL error:nil];
|
|
|
+// [self sendYuyinMsg:model.fileURL.lastPathComponent localtime:loacaltime state:2];
|
|
|
+ [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
|
|
|
}];
|
|
|
|
|
|
|
|
|
@@ -2014,21 +2031,24 @@ static const CGFloat kQuoteViewHeight = 46.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
--(void)sendYuyinMsg:(NSString *)url localtime:(NSString *)loacaltime{
|
|
|
+-(void)sendYuyinMsg:(NSString *)fileName filePth:(NSString *)filePtah localtime:(NSString *)loacaltime state:(NSInteger)index{
|
|
|
NSString *filePath;
|
|
|
- if([url containsString:@"http"]){
|
|
|
- filePath=url;
|
|
|
+ if([fileName containsString:@"http"]){
|
|
|
+ filePath=fileName;
|
|
|
}
|
|
|
else{
|
|
|
- filePath = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",url];
|
|
|
+ filePath = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",fileName];
|
|
|
}
|
|
|
NSString *content=@"【语音】";
|
|
|
NSString *messageType=[NSString stringWithFormat:@"%@",MessageType_voice];
|
|
|
content= [CryptoAES.shareInstance encryptStringL:content];
|
|
|
NSString *type = [NSString stringWithFormat:@"%ld",(long)self.type];
|
|
|
-
|
|
|
+ NSString *localId =loacaltime;
|
|
|
+ if(index==1){
|
|
|
+ localId=@"";
|
|
|
+ }
|
|
|
NSDictionary *dic =@{
|
|
|
- @"id":@"",
|
|
|
+ @"id":localId,
|
|
|
@"messageType":messageType,
|
|
|
@"chatId":self.chatId,
|
|
|
@"fromId":self.userId,
|
|
|
@@ -2043,9 +2063,12 @@ static const CGFloat kQuoteViewHeight = 46.0f;
|
|
|
@"extend":@{
|
|
|
@"url":filePath,
|
|
|
@"time":[NSString stringWithFormat:@"%ld",self->_rcdL],
|
|
|
- @"localurl":@""
|
|
|
+ @"localurl":filePtah
|
|
|
}
|
|
|
};
|
|
|
+ if(index==0){
|
|
|
+ [ChatsStore.shareInstance reciveMsg:dic];
|
|
|
+ }
|
|
|
NSDictionary *sendInfo = @{
|
|
|
@"code":@"2",
|
|
|
@"message":dic,
|
|
|
@@ -2058,7 +2081,10 @@ static const CGFloat kQuoteViewHeight = 46.0f;
|
|
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
NSLog(@"%@", jsonString); // 输出: {"name":"John","age":25}
|
|
|
NSLog(@"----发送语音----");
|
|
|
- [GWebSocket.shareInstance sendMsg:jsonString];
|
|
|
+ if(index==1){
|
|
|
+ [GWebSocket.shareInstance sendMsg:jsonString];
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2435,13 +2461,14 @@ static const CGFloat kQuoteViewHeight = 46.0f;
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
#pragma mark 其他聊天室的消息弹窗
|
|
|
- (void)othersChatMessageAlert:(NSNotification *)notification {
|
|
|
// NSLog(@"othersChatMessageAlert---1");
|
|
|
if ([self isViewLoaded] && self.view.window) {
|
|
|
NSDictionary * msgDict = notification.object;
|
|
|
NSMutableDictionary * mutablemsg = msgDict.mutableCopy;
|
|
|
-// NSLog(@"othersChatMessageAlert---2:%@",mutablemsg);
|
|
|
+ NSLog(@"othersChatMessageAlert---2:%@",mutablemsg);
|
|
|
if (msgDict) {
|
|
|
ChatMessageModel *message = [ChatMessageModel modelWithDictionary:mutablemsg];
|
|
|
if ([message.chatId isEqualToString:self.chatId] || message.isSender ) {
|