ソースを参照

1.初步修复上传多文件时 数组增删中遍历闪退问题

huangxiaodong 10 ヶ月 前
コミット
837f3424ec

+ 5 - 1
创维盒子/双子星云手机/NAS/nasBackupsManager/nasMixBackupsManager.m

@@ -289,7 +289,11 @@
         [self startUpload:paraDict operation:operation data:curData success:^(id  _Nonnull responseObject) {
             frpUploadModel *model = [[frpUploadModel alloc] initWithDictionary:responseObject error:nil];
             if(model && model.position == operation.fileModel.totalBytes){
-                HLog(@"%@上传完成 000",operation.fileModel.filename)
+                HLog(@"%@上传完成 数据正常",operation.fileModel.filename)
+                [weakSelf handleUploadDoneOneFileBy:operation];
+            }
+            else if(model && model.position > operation.fileModel.totalBytes){
+                HLog(@"%@上传完成 数据异常 -- position:%ld -- totalBytes:%ld",operation.fileModel.filename,model.position,operation.fileModel.totalBytes)
                 [weakSelf handleUploadDoneOneFileBy:operation];
             }
             else{

+ 49 - 33
创维盒子/双子星云手机/NAS/nasUploadManager/nasMixUploadManager.m

@@ -71,11 +71,11 @@
     }
     
     //启动上传
-    [self beginUpload];
+    [self beginUploadAfterDeleteOperationBy:nil];
 }
 
 //在添加XX后 启动下载
-- (void)beginUpload
+- (void)beginUploadAfterDeleteOperationBy:(customUploadOperation*)operation
 {
     BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)];
     if(!isCanUseCellular){//不允许流量上传
@@ -101,6 +101,11 @@
     }
     
     @synchronized (self) {
+        
+        if(operation){
+            [self.uploadingOperationArr removeObject:operation];
+        }
+        
         if(self.uploadingOperationArr.count == _maxUploadLoadCount){
             HLog(@"正在上传的数量达到了最大值 %ld",_maxUploadLoadCount)
             return;
@@ -124,6 +129,8 @@
                 
                 //等待下载中的任务
                 [self.uploadWaitingUrlArr removeObjectAtIndex:0];
+                
+                HLog(@"添加一个新的上传任务")
                 //添加到下载中数组
                 [self.uploadingOperationArr addObject:operation];
                 
@@ -159,11 +166,12 @@
             [weakSelf checkFileUploadStateFunAfterNetWith:model WithOperation:operation];
         }
         else{
-            //FileExistRet(-1);
+            HLog(@"isFileExist接口异常:%@",responseObject)
+            [weakSelf handleUploadFailOneFileBy:operation];
         }
     } failure:^(NSError * _Nonnull error) {
         HLog(@"%@",error)
-        //FileExistRet(-1);
+        [weakSelf handleUploadFailOneFileBy:operation];
     }];
     
 }
@@ -172,6 +180,7 @@
 - (void)checkFileUploadStateFunAfterNetWith:(frpFileExistModel*)model WithOperation:(customUploadOperation*)operation
 {
     if(!model){
+        [self handleUploadFailOneFileBy:operation];
         return;
     }
     
@@ -233,6 +242,7 @@
     }
     else{
         HLog(@"获取保存路径失败")
+        [self handleUploadFailOneFileBy:operation];
         return;
     }
     
@@ -266,6 +276,9 @@
                         // 直接得到最终的 NSData 数据
                         if (imageData) {
                             operation.fileModel.imageData = imageData;
+                            if(operation.fileModel.totalBytes == 0){
+                                operation.fileModel.totalBytes = [imageData length];
+                            }
                             [weakSelf  afterGetImageDataFunWithOperation:operation];
                         }
                         else{
@@ -378,7 +391,7 @@
     [self startUpload:paraDict operation:operation data:videoData success:^(id  _Nonnull responseObject) {
         frpUploadModel *model = [[frpUploadModel alloc] initWithDictionary:responseObject error:nil];
         if(model && model.position >= operation.fileModel.totalBytes){
-            HLog(@"%@上传完成 000",operation.fileModel.filename)
+            HLog(@"%@上传完成 001",operation.fileModel.filename)
             [weakSelf handleUploadDoneOneFileBy:operation];
         }
         else{
@@ -470,8 +483,7 @@
 - (void)handleUploadDoneOneFileBy:(customUploadOperation*)operation
 {
     [[NSNotificationCenter defaultCenter] postNotificationName:nasUploadTaskExeEnd object:operation.fileModel];
-    [_uploadingOperationArr removeObject:operation];
-    [self beginUpload];
+    [self beginUploadAfterDeleteOperationBy:operation];
 }
 
 #pragma mark 处理删除失败
@@ -479,8 +491,7 @@
 {
     operation.fileModel.curUploadStateType = uploadStateFail;
     [[NSNotificationCenter defaultCenter] postNotificationName:nasUploadTaskExeError object:operation.fileModel];
-    [_uploadingOperationArr removeObject:operation];
-    [self beginUpload];
+    [self beginUploadAfterDeleteOperationBy:operation];
 }
 
 #pragma mark 根据 asset 获取到图片数据
@@ -681,7 +692,7 @@
         }
     }];
     
-    [self beginUpload];
+    [self beginUploadAfterDeleteOperationBy:nil];
 }
     
 
@@ -737,32 +748,38 @@ didReceiveResponse:(NSURLResponse *)response
     // 32768 = 32KB
     HLog(@"didSendBodyData: %lld--%lld-%lld", bytesSent, totalBytesSent, totalBytesExpectedToSend);
     
+    //最后一片数据不刷新
+    if(totalBytesSent == totalBytesExpectedToSend){
+        return;
+    }
     
-    for (customUploadOperation*operation in _uploadingOperationArr) {
-        if(operation.dataTask == task){
-            operation.fileModel.didUploadBytes += bytesSent;
-            
-            //调整下大小 因为上传的数据 除了data 长度 还包含了 参数大小
-            if(totalBytesSent == totalBytesExpectedToSend){
-                operation.fileModel.didUploadBytes -= (totalBytesExpectedToSend - operation.onceDataLengt);
-            }
-            
-            NSTimeInterval curTime = [[NSDate date] timeIntervalSince1970];
-            NSTimeInterval timeDiff = curTime - operation.preNotTimeInterval;
-            
-            HLog(@"控制刷新时间为1秒:%f",timeDiff);
-            
-            if (operation.preNotTimeInterval <= 0
-                || timeDiff > 0.8 ) {
+    @synchronized (self) {
+        NSMutableArray *preUploadingOperationArr = [_uploadingOperationArr copy];
+        for (customUploadOperation*operation in preUploadingOperationArr) {
+            if(operation.dataTask == task){
+                operation.fileModel.didUploadBytes += bytesSent;
+                
+                //调整下大小 因为上传的数据 除了data 长度 还包含了 参数大小
+                if(totalBytesSent == totalBytesExpectedToSend){
+                    operation.fileModel.didUploadBytes -= (totalBytesExpectedToSend - operation.onceDataLengt);
+                }
+                
+                NSTimeInterval curTime = [[NSDate date] timeIntervalSince1970];
+                NSTimeInterval timeDiff = curTime - operation.preNotTimeInterval;
+                
+                //HLog(@"控制刷新时间为1秒:%f",timeDiff);
                 
-                operation.preNotTimeInterval = curTime;
-                [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:operation.fileModel];
+                if (operation.preNotTimeInterval <= 0
+                    || timeDiff > 0.8 ) {
+                    
+                    operation.preNotTimeInterval = curTime;
+                    [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:operation.fileModel];
+                }
+                
+                break;
             }
-            
-            break;
         }
     }
-    
 }
 
 #pragma mark 取消单个任务
@@ -781,8 +798,7 @@ didReceiveResponse:(NSURLResponse *)response
             if([operation.fileModel.filename isEqualToString:fileModel.filename]){
                 operation.isCancelType = YES;
                 [operation.dataTask cancel];
-                [_uploadingOperationArr removeObject:operation];
-                [self beginUpload];
+                [self beginUploadAfterDeleteOperationBy:operation];
                 break;
             }
         }

+ 2 - 0
创维盒子/双子星云手机/NAS/nasUploadManager/nasUploadFileManager.m

@@ -51,7 +51,9 @@
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
 //        NSLock *lock = [NSLock new];
 //        [lock lock];
+        HLog(@"begin bg_findAsync");
         [uploadFileDataModel bg_findAsync:nasUpLoadFile_tableName limit:0 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
+            HLog(@"end bg_findAsync");
             NSMutableArray *failArr = [NSMutableArray new];
             NSMutableArray *doneArr = [NSMutableArray new];
             NSMutableArray *otherArr = [NSMutableArray new];