|
|
@@ -88,19 +88,26 @@
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- //多个要还要改
|
|
|
+ NSInteger canAddTaskNumber = _maxDownLoadCount - self.downloadingOperationArr.count;
|
|
|
|
|
|
- //创建下载任务
|
|
|
- NSString *downloadUrl = self.downloadWaitingUrlArr.firstObject;
|
|
|
-
|
|
|
- NSURLSession *session = [self creatNewSessionFun];
|
|
|
- customDownloadOperation * operation = [[customDownloadOperation alloc] initWith:downloadUrl session:session];
|
|
|
- [operation.dataTask resume];
|
|
|
-
|
|
|
- //等待下载中的任务
|
|
|
- [self.downloadWaitingUrlArr removeObjectAtIndex:0];
|
|
|
- //添加到下载中数组
|
|
|
- [self.downloadingOperationArr addObject:operation];
|
|
|
+ for (int i=0; i<canAddTaskNumber; i++) {
|
|
|
+
|
|
|
+ if(self.downloadWaitingUrlArr.count >= 1){
|
|
|
+ //创建下载任务
|
|
|
+ NSString *downloadUrl = self.downloadWaitingUrlArr.firstObject;
|
|
|
+
|
|
|
+ NSURLSession *session = [self creatNewSessionFun];
|
|
|
+ customDownloadOperation * operation = [[customDownloadOperation alloc] initWith:downloadUrl session:session];
|
|
|
+ [operation.dataTask resume];
|
|
|
+
|
|
|
+ //等待下载中的任务
|
|
|
+ [self.downloadWaitingUrlArr removeObjectAtIndex:0];
|
|
|
+ //添加到下载中数组
|
|
|
+ [self.downloadingOperationArr addObject:operation];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -436,11 +443,18 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:customDownloadTaskExeError object:nil userInfo:@{@"operation" : operation}];
|
|
|
}
|
|
|
|
|
|
+//外面的下载数据跳的太频繁 控制下
|
|
|
+static int DownloadTaskExeingNotNum = 0;
|
|
|
+
|
|
|
// 重启某一个operation 保存本地 通知外界
|
|
|
- (void)operationDoningWithOperation:(customDownloadOperation *)operation {
|
|
|
HLog(@"DownloadTaskExeing");
|
|
|
-
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:customDownloadTaskExeing object:nil userInfo:@{@"operation" : operation}];
|
|
|
+
|
|
|
+ DownloadTaskExeingNotNum ++;
|
|
|
+ if (DownloadTaskExeingNotNum >= 10) {
|
|
|
+ DownloadTaskExeingNotNum = 0;
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:customDownloadTaskExeing object:nil userInfo:@{@"operation" : operation}];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 等待某一个operation 保存本地 通知外界
|