|
|
@@ -74,12 +74,17 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- KWeakSelf
|
|
|
- //[ShareFileDataModel bg_saveOrUpdateArray:arr];
|
|
|
- [ShareFileDataModel bg_saveOrUpdateArrayAsync:addTaskArr complete:^(BOOL isSuccess) {
|
|
|
- [weakSelf beginDownloadFilesByUrls:addTaskArr];
|
|
|
- complete(isSuccess);
|
|
|
- }];
|
|
|
+ if(addTaskArr.count >0){
|
|
|
+ KWeakSelf
|
|
|
+ //[ShareFileDataModel bg_saveOrUpdateArray:arr];
|
|
|
+ [ShareFileDataModel bg_saveOrUpdateArrayAsync:addTaskArr complete:^(BOOL isSuccess) {
|
|
|
+ [weakSelf beginDownloadFilesByUrls:addTaskArr];
|
|
|
+ complete(isSuccess);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else{//任务下载中
|
|
|
+ complete(YES);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#pragma mark 读取数据库数据
|
|
|
@@ -264,6 +269,13 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
|
|
|
[self handldDownloadDoneDataBy:model];
|
|
|
//HLog(@"下载成功");
|
|
|
+
|
|
|
+ NSMutableArray *allOperation = [[SGDownloadManager shareManager] getAllOperation];
|
|
|
+ NSInteger index = 0;
|
|
|
+ for (SGDownloadOperation *model in allOperation){
|
|
|
+ HLog(@"%ld %ld %@",index,model.downloadState,model.fileName);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)downloadTaskExeError:(NSNotification *)notification
|
|
|
@@ -360,4 +372,81 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
|
|
|
}
|
|
|
|
|
|
+#pragma mark 全部暂停 或者暂停某一个
|
|
|
+- (void)suspendDownloadFileFun:(BOOL)isSuspendAll withModel:(ShareFileDataModel*)dataModel
|
|
|
+{
|
|
|
+ if(isSuspendAll){//全部暂停
|
|
|
+
|
|
|
+ if (_databaseArr && _databaseArr.count == 3) {
|
|
|
+ NSMutableArray *downloadingArr = _databaseArr[0];
|
|
|
+ for (ShareFileDataModel*model in downloadingArr) {
|
|
|
+ model.downloadBoxStateType = downloadBoxStateSuspend;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [[SGDownloadManager shareManager] suspendAllDownloadTask];
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(dataModel){//暂停指定任务
|
|
|
+ if (_databaseArr && _databaseArr.count == 3) {
|
|
|
+ NSMutableArray *downloadingArr = _databaseArr[0];
|
|
|
+ for (ShareFileDataModel*model in downloadingArr) {
|
|
|
+
|
|
|
+ if(model.bg_id.integerValue == dataModel.bg_id.integerValue){
|
|
|
+ model.downloadBoxStateType = downloadBoxStateSuspend;
|
|
|
+
|
|
|
+ NSString *urlString = model.fileUrl;
|
|
|
+ NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+ [[SGDownloadManager shareManager] supendDownloadWithUrl:requestURLEncodedString];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 重新开始下载
|
|
|
+- (void)reDownloadFileFunBy:(NSMutableArray*)arr withAll:(BOOL)isAllType
|
|
|
+{
|
|
|
+ //目前只允许一个下载 所以先暂停任务
|
|
|
+ //[[SGDownloadManager shareManager] suspendAllDownloadTask];
|
|
|
+
|
|
|
+ if(isAllType){
|
|
|
+ [[SGDownloadManager shareManager] startAllDownloadTask];
|
|
|
+
|
|
|
+// if (_databaseArr && _databaseArr.count == 3) {
|
|
|
+// NSMutableArray *downloadingArr = _databaseArr[0];
|
|
|
+// ShareFileDataModel*firstmodel = nil;
|
|
|
+// for (ShareFileDataModel*model in downloadingArr) {
|
|
|
+// model.downloadBoxStateType = downloadBoxStateDownloadloading;
|
|
|
+//
|
|
|
+// if(!firstmodel){
|
|
|
+// firstmodel = model;
|
|
|
+// [self reDownloadFileFunBy:firstmodel];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for (ShareFileDataModel*model in arr) {
|
|
|
+ model.downloadBoxStateType = downloadBoxStateDownloadloading;
|
|
|
+ [self reDownloadFileFunBy:model];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark 重新开启下载任务
|
|
|
+- (void)reDownloadFileFunBy:(ShareFileDataModel*)dataModel
|
|
|
+{
|
|
|
+ __block NSString *urlString = dataModel.fileUrl;
|
|
|
+ NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+ if(urlString){
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ [[SGDownloadManager shareManager] startDownLoadWithUrl:requestURLEncodedString];
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
@end
|