|
@@ -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];
|
|
|
}
|