Forráskód Böngészése

1.上传bug跟进---未处理完成

huangxiaodong 9 hónapja%!(EXTRA string=óta)
szülő
commit
25600506ff

+ 4 - 1
创维盒子/双子星云手机/AppDelegate/Config/Notification.h

@@ -63,9 +63,12 @@
 #define lockBypwdNotification                 @"lockBypwdNot"
 
 
-/*上传文件更新通知*/
+/*上传文件(成功 失败 删除)更新通知*/
 #define uploadFileRefreshNotification                 @"uploadFileRefreshNot"
 
+/*上传文件进度更新通知*/
+#define uploadFileUploadingNotification                 @"uploadFileUploadingNot"
+
 /* 上传文件暂停全部通知*/
 #define uploadFileSuspendAllNotification                 @"uploadFileSuspendAllNot"
 /* 上传文件通知*/

+ 7 - 7
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileRecordViewController.m

@@ -686,13 +686,13 @@
     
     //HLog(@"传输列表的上传任务:%@",uploadingArr);
     
-    for (int i=0; i<uploadingArr.count; i++) {
-        uploadFileDataModel*preModel = uploadingArr[i];
-        if(preModel.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
-            [_leftTableView.uploadingArr replaceObjectAtIndex:i withObject:uploadFileDataMod];
-            break;
-        }
-    }
+//    for (int i=0; i<uploadingArr.count; i++) {
+//        uploadFileDataModel*preModel = uploadingArr[i];
+//        if(preModel.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
+//            [_leftTableView.uploadingArr replaceObjectAtIndex:i withObject:uploadFileDataMod];
+//            break;
+//        }
+//    }
     
     if(uploadFileDataMod.curUploadStateType == uploadStateDone
        || uploadFileDataMod.curUploadStateType == uploadStateFail){

+ 130 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileView/uploadFileRecordCell.m

@@ -33,6 +33,8 @@
     if (self)
     {
         [self drawView];
+        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileUploadingNotFun:) name:uploadFileUploadingNotification object:nil];
     }
     
     return self;
@@ -476,4 +478,132 @@
     });
 }
 
+#pragma mark 上传通知
+- (void)uploadFileUploadingNotFun:(NSNotification *)not
+{
+    if(_curUploadFileDataModel
+       && _curUploadFileDataModel.curUploadStateType != uploadStateWait
+       && _curUploadFileDataModel.curUploadStateType != uploadStateUploading){
+        return;
+    }
+    
+    uploadFileDataModel *model = [not object];
+    if(!model)return;
+    
+    if(model.bg_id.integerValue != _curUploadFileDataModel.bg_id.integerValue){
+        return;
+    }
+    
+    if(model.curUploadStateType != uploadStateUploading){
+        return;
+    }
+    
+    if(![model.filename isEqualToString:_curUploadFileDataModel.filename]){
+        return;
+    }
+    
+    model.curTimeInterval = [[NSDate date] timeIntervalSince1970];
+    
+    KWeakSelf
+    mainBlock(^{
+        [weakSelf updateDataUploadingBy:model];
+    });
+}
+
+
+#pragma mark 更新上传进度
+- (void)updateDataUploadingBy:(uploadFileDataModel*)model{
+    
+    NSString * speedStr = nil;
+    //进度设置
+    CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
+    
+    NSInteger totalSize = model.totalBytes;
+    if(totalSize == 0.0){
+        totalSize += 0.0001;
+    }
+    
+    CGFloat curProgress = model.didUploadBytes/(totalSize*1.0);
+    
+    if(curProgress > 1){
+        curProgress = 1;
+    }
+    
+    frame.size.width =  frame.size.width * curProgress;
+    
+    if (isnan(frame.size.width))
+    {
+        HLog(@"计算出错了");
+        frame.size.width = 10.0;
+    }
+    
+    _progressSelectView.frame = frame;
+    //_glayer.frame = frame;
+    
+    NSString * totalSizeStr = nil;
+    NSInteger totalSize_k = totalSize / 1024;
+    if(totalSize_k < 1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
+    }
+    else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
+        
+    }
+    else{
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
+    }
+    
+    NSString * didUploadStr = nil;
+    NSInteger didUploadSize_k = model.didUploadBytes / 1024;
+    if(didUploadSize_k < 1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
+    }
+    else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
+        
+    }
+    else{
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
+    }
+    
+    _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
+
+    if(model.curUploadStateType == uploadStateUploading){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
+        _fileSpeedlabel.hidden = NO;
+    
+        if(_curUploadFileDataModel.preTimeInterval <= 0
+           || _curUploadFileDataModel.didUploadBytes == _curUploadFileDataModel.preDidUploadBytes){
+            //_fileSpeedlabel.text = @"--";
+        }
+        else{
+            NSTimeInterval  timers = _curUploadFileDataModel.curTimeInterval - _curUploadFileDataModel.preTimeInterval;
+            
+            if(timers > 0){
+                //long speed= 1*1024*1024 / timers;
+                
+                long speed= (_curUploadFileDataModel.didUploadBytes - _curUploadFileDataModel.preDidUploadBytes) / timers;
+                
+                
+                NSInteger speed_k = speed / (1024);
+                if(speed_k < 1024){
+                    speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
+                }
+                else {
+                    speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
+                }
+                
+                //HLog(@"22211:%@",_fileSpeedlabel.description);
+            }
+        }
+        
+        _curUploadFileDataModel.preTimeInterval = model.curTimeInterval;
+        _curUploadFileDataModel.preTimeInterval = model.didUploadBytes;
+    }
+
+    if (speedStr) {
+        self->_fileSpeedlabel.text = speedStr;
+    }
+}
+
 @end

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

@@ -761,7 +761,6 @@ didReceiveResponse:(NSURLResponse *)response
                 
                 [[nasBackupsManager shareInstance] changeBackupsFileStateFun];
                 
-//                [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:operation.fileModel];
                 operation.i = 0;
             }
             

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

@@ -123,6 +123,9 @@
     
     NSInteger canAddTaskNumber = _maxUploadLoadCount - self.uploadingOperationArr.count;
     
+    //新添加的任务
+    NSMutableArray *newTaskArr = [NSMutableArray new];
+    
     [_arrayLock lock];
     for (int i=0; i<canAddTaskNumber; i++) {
         
@@ -130,22 +133,32 @@
             //创建上传任务
             uploadFileDataModel *WaitingModel = self.uploadWaitingUrlArr.firstObject;
             
-            __block customUploadOperation * operation =  [customUploadOperation new];
+            customUploadOperation * operation =  [customUploadOperation new];
             operation.fileModel = WaitingModel;
             
             //等待下载中的任务
             [self.uploadWaitingUrlArr removeObjectAtIndex:0];
             
-            HLog(@"添加一个新的上传任务")
+            HLog(@"添加一个新的上传任务 %@",self.uploadingOperationArr)
             //添加到下载中数组
             [self.uploadingOperationArr addObject:operation];
             
-            [self checkFileUploadStateWithOperation:operation];
+            //[self checkFileUploadStateWithOperation:operation];
+            
+            [newTaskArr addObject:operation];
             
             //[weakSelf handleTaskDidUploadWith:operation withState:state];
         }
         
     }
+    
+    //开始检测新的上传任务
+    for (customUploadOperation * operation  in newTaskArr) {
+        [self checkFileUploadStateWithOperation:operation];
+    }
+    
+    [newTaskArr removeAllObjects];
+    
     [_arrayLock unlock];
     
 }
@@ -706,7 +719,7 @@
         [[iToast makeText:NSLocalizedString(@"File_upload_file_already_exists",nil)] show];
     }
     
-    
+    HLog(@"上传的文件已存在 删除任务:_uploadingOperationArr:%@",_uploadingOperationArr);
     [self.uploadingOperationArr removeObject:operation];
     
     NSMutableArray *delArr = [NSMutableArray new];
@@ -774,38 +787,34 @@ didReceiveResponse:(NSURLResponse *)response
     // 32768 = 32KB
     HLog(@"didSendBodyData: %lld--%lld-%lld", bytesSent, totalBytesSent, totalBytesExpectedToSend);
     
-    //最后一片数据不刷新
-//    if(totalBytesSent == totalBytesExpectedToSend){
-//        return;
-//    }
-    
-    
-//    [_arrayLock lock];
-//    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 ) {
-//                
-//                operation.preNotTimeInterval = curTime;
-//                [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:operation.fileModel];
-//            }
-//            
-//            break;
-//        }
-//    }
-//    [_arrayLock unlock];
+    [_arrayLock lock];
+    for (customUploadOperation*operation in _uploadingOperationArr) {
+        HLog(@"正在遍历数组 _uploadingOperationArr:%@",_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 ) {
+                
+                operation.preNotTimeInterval = curTime;
+                [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileUploadingNotification object:operation.fileModel];
+            }
+            
+            break;
+        }
+    }
+    [_arrayLock unlock];
 }
 
 #pragma mark 取消单个任务
@@ -816,6 +825,7 @@ didReceiveResponse:(NSURLResponse *)response
     [_arrayLock lock];
     
     for (customUploadOperation*operation in _uploadingOperationArr) {
+        HLog(@"正在遍历数组 _uploadingOperationArr:%@",_uploadingOperationArr);
         if([operation.fileModel.filename isEqualToString:fileModel.filename]){
             operation.isCancelType = YES;
             [operation.dataTask cancel];
@@ -846,6 +856,7 @@ didReceiveResponse:(NSURLResponse *)response
     [_uploadWaitingUrlArr removeAllObjects];
     
     for (customUploadOperation*operation in _uploadingOperationArr) {
+        HLog(@"正在遍历数组 _uploadingOperationArr:%@",_uploadingOperationArr);
         operation.isCancelType = YES;
         [operation.dataTask cancel];
     }

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

@@ -275,6 +275,7 @@
 #pragma mark 上传完成 清理缓存
 - (void)deleteCacheDataBy:(uploadFileDataModel*)uploadFileDataMod
 {
+    HLog(@"上传--清理缓存")
     uploadFileDataMod.imageData = nil;
     uploadFileDataMod.videoData = nil;
     
@@ -290,6 +291,7 @@
 {
     //test code
     //return;
+    HLog(@"更新数据状态")
     
     if(dataModel.curUploadStateType == uploadStateDone){
         [self handleDatabaseArrDeleteObjectInUploading:dataModel];
@@ -318,16 +320,17 @@
     }];
         
     
-//    if(!_isSuspendType || dataModel.curUploadStateType != uploadStateSuspend){
-//        HLog(@"nasUploadFileChangeingOneFileFunBy uploadFileRefreshNotification")
-//        [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:dataModel];
-//    }
+    if(!_isSuspendType || dataModel.curUploadStateType != uploadStateSuspend){
+        HLog(@"nasUploadFileChangeingOneFileFunBy uploadFileRefreshNotification")
+        [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:dataModel];
+    }
     
 }
 
 #pragma mark 删除上传中的任务
 - (void)handleDatabaseArrDeleteObjectInUploading:(uploadFileDataModel*)model
 {
+    HLog(@"删除上传中的任务")
     NSLock *lock = [NSLock new];
     [lock lock];
     if(_databaseArr && _databaseArr.count == 3 ){
@@ -353,6 +356,7 @@
 #pragma mark 添加任务到上传完成
 - (void)handleDatabaseArrAddObjectInDone:(uploadFileDataModel*)model
 {
+    HLog(@"添加任务到上传完成")
     NSLock *lock = [NSLock new];
     [lock lock];
     if(_databaseArr && _databaseArr.count == 3 ){
@@ -367,6 +371,7 @@
 #pragma mark 添加任务到上传失败
 - (void)handleDatabaseArrAddObjectInFail:(uploadFileDataModel*)model
 {
+    HLog(@"添加任务到上传失败")
     NSLock *lock = [NSLock new];
     [lock lock];
     if(_databaseArr && _databaseArr.count == 3 ){

+ 4 - 1
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager.m

@@ -865,7 +865,10 @@
 {
     //HLog(@"onIceConnectedFromPeerName:%@",buffer.data);
     if(buffer && buffer.data){
-        [self handleWebRtcMsgResponseBy:buffer.data];
+        KWeakSelf
+        mainBlock(^{
+            [weakSelf handleWebRtcMsgResponseBy:buffer.data];
+        });
     }
 }