Browse Source

完善文件传输

ganzf 5 tháng trước cách đây
mục cha
commit
11fcdc8ca0

+ 3 - 1
AIIM/AIIM/Common/Network/aliOSS/OSSManager.m

@@ -333,7 +333,7 @@
                     NSURL *loaclUrl = [NSURL URLWithString:localPath];
                     NSURL *loaclUrl = [NSURL URLWithString:localPath];
                     NSString *url = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",loaclUrl.lastPathComponent];
                     NSString *url = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",loaclUrl.lastPathComponent];
                     [mextend setObject:url forKey:@"url"];
                     [mextend setObject:url forKey:@"url"];
-                    
+                    [mextend setObject:[NSNumber numberWithInt:0] forKey:@"fileError"];
                     [mmsg setObject:mextend forKey:@"extend"];
                     [mmsg setObject:mextend forKey:@"extend"];
                     [mmsg setObject:@"" forKey:@"id"];
                     [mmsg setObject:@"" forKey:@"id"];
                 }
                 }
@@ -344,6 +344,8 @@
                     
                     
                     [mmsg setObject:mextend forKey:@"extend"];
                     [mmsg setObject:mextend forKey:@"extend"];
                     [mmsg setObject:@"" forKey:@"id"];
                     [mmsg setObject:@"" forKey:@"id"];
+                    [ChatsStore.shareInstance reciveMsg:mmsg];
+                    return;
                 }
                 }
                 
                 
                 
                 

+ 1 - 0
AIIM/AIIM/Common/Store/ChatsStore.h

@@ -23,6 +23,7 @@
 + (ChatsStore *_Nonnull)shareInstance;
 + (ChatsStore *_Nonnull)shareInstance;
 @property (nonatomic,weak) id <ChatsStoreDelegate> delegate;
 @property (nonatomic,weak) id <ChatsStoreDelegate> delegate;
 
 
+@property (nonatomic) NSInteger reloadC;
 @property (nonatomic,strong) NSMutableArray * _Nullable msgList;
 @property (nonatomic,strong) NSMutableArray * _Nullable msgList;
 @property (nonatomic,strong) NSString * _Nullable chatId;
 @property (nonatomic,strong) NSString * _Nullable chatId;
 @property (nonatomic) NSInteger lastreadTime;
 @property (nonatomic) NSInteger lastreadTime;

+ 16 - 1
AIIM/AIIM/Common/Store/ChatsStore.m

@@ -118,7 +118,13 @@
 -(void)reloadData:(NSString *_Nonnull)chatId type:(NSInteger)type{
 -(void)reloadData:(NSString *_Nonnull)chatId type:(NSInteger)type{
 //    NSLog(@"chatId:%@,%ld",chatId,(long)type);
 //    NSLog(@"chatId:%@,%ld",chatId,(long)type);
     [self reloadData:chatId];
     [self reloadData:chatId];
+    _reloadC=0;
+    [self loadOutLineMsg:chatId type:type];
+}
+
+-(void)loadOutLineMsg:(NSString *_Nonnull)chatId type:(NSInteger)type{
     [ChatNetApi getOutLineMsg:chatId type:type succ:^(int code, NSDictionary *res) {
     [ChatNetApi getOutLineMsg:chatId type:type succ:^(int code, NSDictionary *res) {
+        self->_reloadC=4;
         NSArray *array = res[@"data"];
         NSArray *array = res[@"data"];
 //        NSLog(@"getOutLineMsg2 res:%lu",(unsigned long)array.count);
 //        NSLog(@"getOutLineMsg2 res:%lu",(unsigned long)array.count);
         if(array.count>0){
         if(array.count>0){
@@ -145,10 +151,19 @@
         }
         }
         
         
     } fail:^(NSError * _Nonnull error) {
     } fail:^(NSError * _Nonnull error) {
-        ;
+//        [MBProgressHUD showWithText:@"网络错误"];
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+            if(self->_reloadC<3){
+                self->_reloadC=self->_reloadC+1;
+                [self loadOutLineMsg:chatId type:type];
+            }
+        });
     }];
     }];
 }
 }
 
 
+
+
+
 -(void)reloadQunData:(NSString *_Nonnull)chatId type:(NSInteger)type{
 -(void)reloadQunData:(NSString *_Nonnull)chatId type:(NSInteger)type{
     
     
     NSDate *now = [NSDate date];
     NSDate *now = [NSDate date];

+ 63 - 20
AIIM/AIIM/Controller/chat/ChatController.m

@@ -1389,27 +1389,62 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     NSString *localtime = msg[@"localtime"];
     NSString *localtime = msg[@"localtime"];
     NSString *messageType = msg[@"messageType"];
     NSString *messageType = msg[@"messageType"];
     if([messageType isEqualToString:MessageType_file]||[messageType isEqualToString:MessageType_image]||[messageType isEqualToString:MessageType_video]) {
     if([messageType isEqualToString:MessageType_file]||[messageType isEqualToString:MessageType_image]||[messageType isEqualToString:MessageType_video]) {
+        if([OSSManager.sharedManager isuploadTanck:localtime]){
+            return;
+        }
         for (NSDictionary *item in self.msgList) {
         for (NSDictionary *item in self.msgList) {
             
             
-            if([OSSManager.sharedManager isuploadTanck:localtime]){
-                return;
-            }
-            NSDictionary *extend =item[@"extend"];
-            NSString *url =extend[@"url"];
-            if([url isEqualToString:@""]){
-                NSString *savedPath =extend[@"localurl"];
-                NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
-                ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
-                model.fileURL = fileUrl;
-                model.filePath = savedPath;
-                [self OSSuploadFile:model thrid:localtime];
-                NSLog(@"重发文件");
+            NSString *itlocaltime =item[@"localtime"];
+            if([localtime isEqualToString:itlocaltime]){
+                NSLog(@"canResend2:%@",item);
+                if(![item[@"id"] isEqualToString:item[@"localtime"]]){
+                    return;
+                }
+                NSDictionary *extend =item[@"extend"];
+                NSString *url =extend[@"url"];
+                if([url isEqualToString:@""]){
+                    NSString *savedPath =extend[@"localurl"];
+                    NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
+                    ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
+                    model.fileURL = fileUrl;
+                    model.filePath = savedPath;
+                    [self OSSuploadFile:model thrid:localtime];
+                    NSLog(@"重发文件");
+                    [self FileReUpload:localtime];
+                }
+                
             }
             }
         }
         }
     }
     }
 }
 }
 
 
 
 
+-(void)FileReUpload:(NSString *)localtime{
+    [GDBManager.shareInstance selectLocalmsgWithLocaltime:localtime succ:^(NSArray * _Nullable array) {
+        NSLog(@"selectLocalmsgWithLocaltime:%@",array);
+        
+        if(array){
+            if(array.count>0){
+                NSDictionary *msg =array[0];
+                NSString *msgtype = msg[@"messageType"];
+                
+                if (([msgtype isEqualToString:MessageType_Del]||[msgtype isEqualToString:MessageType_CallBack2])) {
+                    return;
+                }
+                NSDictionary *extend=msg[@"extend"];
+                NSMutableDictionary *mextend = [extend mutableCopy];
+                [mextend setObject:[NSNumber numberWithInt:0] forKey:@"fileError"];
+                NSMutableDictionary *mmsg = [msg mutableCopy];
+                [mmsg setObject:mextend forKey:@"extend"];
+                [ChatsStore.shareInstance reciveMsg:mmsg];
+            }
+        }
+    } fail:^(NSString * _Nullable error) {
+        ;
+    }];
+}
+
+
 //重发消息
 //重发消息
 -(void)resendMsg:(NSDictionary *)msg{
 -(void)resendMsg:(NSDictionary *)msg{
     if(![self canResend:msg]){
     if(![self canResend:msg]){
@@ -1645,11 +1680,16 @@ static const CGFloat kQuoteViewHeight = 46.0f;
         if ([urls indexOfObject:url] > 9) {
         if ([urls indexOfObject:url] > 9) {
             break;
             break;
         }
         }
-        ChatFileModel * model = [[ChatFileModel alloc] initWithURL:url];
-//        ChatFileModel * model = [[ChatFileModel alloc] initWithName:[FileInfoUtils getFileNameWithURL:url] size:[FileInfoUtils getFileSizeStringWithURL:url error:nil] isOversize:[FileInfoUtils isFileGreaterThan100MB:url error:nil]];
-        model.fileURL = url;
-        model.filePath = [url path];
-        [fileArray addObject:model];
+        NSLog(@"url:%@",url);
+        
+        NSString *savedPath = [self saveFileToDocumentsDirectory:url];
+        if(savedPath.length>0){
+            NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
+            ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
+            model.fileURL = fileUrl;
+            model.filePath = savedPath;
+            [fileArray addObject:model];
+        }
     }
     }
     dispatch_async(dispatch_get_main_queue(), ^{
     dispatch_async(dispatch_get_main_queue(), ^{
         [self handleMediaData:fileArray];
         [self handleMediaData:fileArray];
@@ -1756,7 +1796,8 @@ static const CGFloat kQuoteViewHeight = 46.0f;
         extend=@{
         extend=@{
             @"url":@"",
             @"url":@"",
             @"fileName":filePath.lastPathComponent,
             @"fileName":filePath.lastPathComponent,
-            @"localurl":path
+            @"localurl":path,
+            @"fileError":[NSNumber numberWithInt:0]
         };
         };
         msgt=@{
         msgt=@{
             @"messageType":messageType,
             @"messageType":messageType,
@@ -2005,6 +2046,8 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     } else {
     } else {
         [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
         [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
         NSLog(@"文件复制失败: %@", error.localizedDescription);
         NSLog(@"文件复制失败: %@", error.localizedDescription);
+        [MBProgressHUD showWithText:@"語音發送異常請重試"];
+        return;
     }
     }
     NSLog(@"destinationPath:%@",destinationPath);
     NSLog(@"destinationPath:%@",destinationPath);
     
     
@@ -2054,7 +2097,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
         @"timestamp":loacaltime,
         @"timestamp":loacaltime,
         @"mine":[NSNumber numberWithBool:YES],
         @"mine":[NSNumber numberWithBool:YES],
         @"extend":@{
         @"extend":@{
-            @"url":filePath,
+            @"url":@"",
             @"time":[NSString stringWithFormat:@"%ld",self->_rcdL],
             @"time":[NSString stringWithFormat:@"%ld",self->_rcdL],
             @"localurl":filePtah
             @"localurl":filePtah
         }
         }

+ 96 - 32
AIIM/AIIM/Controller/chat/chetCell/ChatMessageModel.m

@@ -95,6 +95,11 @@
     if (fileError!=0) {
     if (fileError!=0) {
         self.fileError = fileError;
         self.fileError = fileError;
     }
     }
+    else{
+        if(self.url.length>0){
+            self.fileError = 0;
+        }
+    }
     
     
     
     
     //合并转发
     //合并转发
@@ -428,31 +433,61 @@
             }
             }
             return;
             return;
         }
         }
-        
-        [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
-            if(res!=nil){
-                NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
-                NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
-                [extend setObject:res[@"filePath"] forKey:@"localurl"];
-                [mutableDict setObject:extend forKey:@"extend"];
-                self.localurl = res[@"filePath"];
-                NSDictionary *NewMsg = [mutableDict copy];
-                [ChatsStore.shareInstance reciveMsg:NewMsg];
-                if (loading) {
-                    loading(100);
+        else{
+            if(self.url&&self.url.length != 0){
+                
+                NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
+                NSURL *tempUrl = [NSURL URLWithString:self.url];
+                NSString *fileName = tempUrl.lastPathComponent;
+                NSString *fileExtension = [fileName pathExtension];
+                NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
+                documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
+                NSLog(@"文件已经存在本地1-:%@",documentsDirectoryURL.path);
+                if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
+                    NSLog(@"文件已经存在本地2-:%@",documentsDirectoryURL.path);
+                    NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
+                    NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
+                    [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
+                    [mutableDict setObject:extend forKey:@"extend"];
+                    self.localurl = documentsDirectoryURL.path;
+                    NSDictionary *NewMsg = [mutableDict copy];
+                    [ChatsStore.shareInstance reciveMsg:NewMsg];
+                    if (loading) {
+                        loading(100);
+                    }
+                }
+                else{
+                    [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
+                        if(res!=nil){
+                            NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
+                            NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
+                            [extend setObject:res[@"filePath"] forKey:@"localurl"];
+                            [mutableDict setObject:extend forKey:@"extend"];
+                            self.localurl = res[@"filePath"];
+                            NSDictionary *NewMsg = [mutableDict copy];
+                            [ChatsStore.shareInstance reciveMsg:NewMsg];
+                            if (loading) {
+                                loading(100);
+                            }
+                        }
+                        else{
+                            if (code>=0&&code<200) {
+                                if (loading) {
+                                    loading(code);
+                                }
+                            }
+                        }
+                    } fail:^(NSError * _Nonnull error) {
+                        NSLog(@"error:%@",error);
+                    }];
                 }
                 }
             }
             }
             else{
             else{
-                if (code>=0&&code<200) {
-                    if (loading) {
-                        loading(code);
-                    }
+                if (loading) {
+                    loading(0);
                 }
                 }
             }
             }
-        } fail:^(NSError * _Nonnull error) {
-            NSLog(@"error:%@",error);
-            NSLog(@"%@",self.url);
-        }];
+        }
     }
     }
 }
 }
 
 
@@ -472,13 +507,22 @@
             return;
             return;
         }
         }
         
         
-        [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
-            if(res!=nil){
+        if(self.url&&self.url.length != 0){
+            
+            NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
+            NSURL *tempUrl = [NSURL URLWithString:self.url];
+            NSString *fileName = tempUrl.lastPathComponent;
+            NSString *fileExtension = [fileName pathExtension];
+            NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
+            documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
+            NSLog(@"文件已经存在本地1-:%@",documentsDirectoryURL.path);
+            if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
+                NSLog(@"文件已经存在本地2-:%@",documentsDirectoryURL.path);
                 NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
                 NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
                 NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
                 NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
-                [extend setObject:res[@"filePath"] forKey:@"localurl"];
+                [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
                 [mutableDict setObject:extend forKey:@"extend"];
                 [mutableDict setObject:extend forKey:@"extend"];
-                self.localurl = res[@"filePath"];
+                self.localurl = documentsDirectoryURL.path;
                 NSDictionary *NewMsg = [mutableDict copy];
                 NSDictionary *NewMsg = [mutableDict copy];
                 [ChatsStore.shareInstance reciveMsg:NewMsg];
                 [ChatsStore.shareInstance reciveMsg:NewMsg];
                 if (loading) {
                 if (loading) {
@@ -486,16 +530,36 @@
                 }
                 }
             }
             }
             else{
             else{
-                if (code>=0&&code<200) {
-                    if (loading) {
-                        loading(code);
+                [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
+                    if(res!=nil){
+                        NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
+                        NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
+                        [extend setObject:res[@"filePath"] forKey:@"localurl"];
+                        [mutableDict setObject:extend forKey:@"extend"];
+                        self.localurl = res[@"filePath"];
+                        NSDictionary *NewMsg = [mutableDict copy];
+                        [ChatsStore.shareInstance reciveMsg:NewMsg];
+                        if (loading) {
+                            loading(100);
+                        }
                     }
                     }
-                }
+                    else{
+                        if (code>=0&&code<200) {
+                            if (loading) {
+                                loading(code);
+                            }
+                        }
+                    }
+                } fail:^(NSError * _Nonnull error) {
+                    NSLog(@"error:%@",error);
+                }];
             }
             }
-        } fail:^(NSError * _Nonnull error) {
-            NSLog(@"error:%@",error);
-            NSLog(@"%@",self.url);
-        }];
+        }
+        else{
+            if (loading) {
+                loading(0);
+            }
+        }
     }
     }
 }
 }
 
 

+ 0 - 9
AIIM/AIIM/Controller/chat/chetCell/chatCellView.m

@@ -873,12 +873,6 @@ static const CGFloat kMediaCornerRadius = 4.0f;
     _thumbnailView.image  = nil;
     _thumbnailView.image  = nil;
     _loadingImg.image = nil;
     _loadingImg.image = nil;
     
     
-//    if(_messageModel.fileError==1){
-//        
-//        self.thumbnailView.image = [UIImage imageNamed:@"pictrue_load_fail"];
-//        _currentContentView = _videoContentView;
-//        return;
-//    }
     
     
     weakSelf(self);
     weakSelf(self);
     if (_messageModel.videoThumbnailImage) {
     if (_messageModel.videoThumbnailImage) {
@@ -1654,9 +1648,6 @@ static const CGFloat kMediaCornerRadius = 4.0f;
         AVAudioSession *audioSession = [AVAudioSession sharedInstance];
         AVAudioSession *audioSession = [AVAudioSession sharedInstance];
         [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
         [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
         [audioSession setActive:YES error:nil];
         [audioSession setActive:YES error:nil];
-        
-        
-        
         AVPlayerItem *pitem = [AVPlayerItem playerItemWithURL:Url];
         AVPlayerItem *pitem = [AVPlayerItem playerItemWithURL:Url];
         
         
         //AVPlayerItem *pitem = [[AVPlayerItem alloc] initWithURL:Url];
         //AVPlayerItem *pitem = [[AVPlayerItem alloc] initWithURL:Url];

+ 14 - 12
AIIM/AIIM/Controller/login/GLoginController.m

@@ -143,17 +143,13 @@
         
         
         return;
         return;
     }
     }
+    [MBProgressHUD showLoadingWithText:@"" inView:self.view];
     [self loginAct];
     [self loginAct];
     
     
 }
 }
 
 
 -(void)loginAct{
 -(void)loginAct{
-    
-    if(![[AppDelegate sharedInstance] NetReachableState]){
-        [MBProgressHUD showWithText:NSLocalizedString(@"Login_network_alter", @"")];
-        return;
-    }
-    
+
     [self.view endEditing:YES];
     [self.view endEditing:YES];
     NSString *userid = self.userId.text;
     NSString *userid = self.userId.text;
     NSString *password = self.password.text;
     NSString *password = self.password.text;
@@ -167,6 +163,8 @@
     
     
     [UserNetApi login:ps succ:^(int code, NSDictionary * res) {
     [UserNetApi login:ps succ:^(int code, NSDictionary * res) {
         NSLog(@"%@",res);
         NSLog(@"%@",res);
+        self->_reLoginC=4;
+        [MBProgressHUD hideAllTipsInView:self.view];
         NSString *codes = res[@"code"];
         NSString *codes = res[@"code"];
         if(codes.intValue!=200){
         if(codes.intValue!=200){
             [MBProgressHUD showWithText:res[@"msg"]];
             [MBProgressHUD showWithText:res[@"msg"]];
@@ -185,12 +183,15 @@
         }
         }
     } fail:^(NSError * _Nonnull error) {
     } fail:^(NSError * _Nonnull error) {
         NSLog(@"--%@",error);
         NSLog(@"--%@",error);
-        if(self->_reLoginC<3){
-            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+            if(self->_reLoginC<3){
                 self->_reLoginC=self->_reLoginC+1;
                 self->_reLoginC=self->_reLoginC+1;
-                
-            });
-        }
+                [self loginAct];
+            }
+            else{
+                [MBProgressHUD hideAllTipsInView:self.view];
+            }
+        });
     }];
     }];
 }
 }
 
 
@@ -248,6 +249,7 @@
             if([gcode intValue]==200){
             if([gcode intValue]==200){
                 NSLog(@"ps:%@",ps);
                 NSLog(@"ps:%@",ps);
                 [MBProgressHUD showWithText:@"登录成功"];
                 [MBProgressHUD showWithText:@"登录成功"];
+                [MBProgressHUD hideAllTipsInView:self.view];
                 [UDManager.shareInstance setSDManager:ps[@"id"] key:dkuserId];
                 [UDManager.shareInstance setSDManager:ps[@"id"] key:dkuserId];
                 [UDManager.shareInstance setDDManager:ps key:dkuserinfo];
                 [UDManager.shareInstance setDDManager:ps key:dkuserinfo];
                 [[NSNotificationCenter defaultCenter] postNotificationName: nkonLoginSucc object:nil];
                 [[NSNotificationCenter defaultCenter] postNotificationName: nkonLoginSucc object:nil];
@@ -256,7 +258,7 @@
         } fail:^(NSError * _Nonnull error) {
         } fail:^(NSError * _Nonnull error) {
             NSLog(@"%@", error);
             NSLog(@"%@", error);
             // 使用GCD创建一个在3秒后执行的定时器
             // 使用GCD创建一个在3秒后执行的定时器
-            
+            [MBProgressHUD hideAllTipsInView:self.view];
         }];
         }];
     }
     }
 }
 }