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