|
@@ -44,6 +44,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
config.saveRootPath = path;
|
|
|
//config.uid = @"100006";
|
|
|
config.uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
|
|
|
+ HLog(@"%@",config.uid);
|
|
|
config.maxTaskCount = 1;
|
|
|
config.taskCachekMode = YCDownloadTaskCacheModeDefault;//YCDownloadTaskCacheModeKeep;
|
|
|
config.launchAutoResumeDownload = NO;
|
|
@@ -69,6 +70,47 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#pragma mark 删除多余的任务 比如数据删除了 但是任务还在
|
|
|
+- (void)checkDownloadTaskFun{
|
|
|
+ NSArray *allDownItemArr = [YCDownloadManager downloadList];
|
|
|
+
|
|
|
+ NSArray* downloadingArr = nil;
|
|
|
+ NSArray* downloadingFail = nil;
|
|
|
+ if(_databaseArr && _databaseArr.count == 3){
|
|
|
+ downloadingArr = _databaseArr[0];
|
|
|
+ downloadingFail = _databaseArr[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ for (YCDownloadItem *item in allDownItemArr) {
|
|
|
+
|
|
|
+ BOOL isNeedStopType = YES;
|
|
|
+
|
|
|
+ //解码
|
|
|
+ NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+
|
|
|
+ if(downloadingArr && downloadingArr.count > 0){
|
|
|
+ for (ShareFileDataModel*dataModel in downloadingArr) {
|
|
|
+ if([urlString isEqualToString:dataModel.fileUrl]){
|
|
|
+ isNeedStopType = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(downloadingFail && downloadingFail.count > 0){
|
|
|
+ for (ShareFileDataModel*dataModel in downloadingFail) {
|
|
|
+ if([urlString isEqualToString:dataModel.fileUrl]){
|
|
|
+ isNeedStopType = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isNeedStopType){
|
|
|
+ HLog(@"停止多的下载任务:%@",item.downloadURL);
|
|
|
+ [YCDownloadManager stopDownloadWithItem:item];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
//添加保存记录
|
|
|
- (void)addBoxDownloadRecordFunBy:(NSArray*)arr complete:(custom_complete_B)complete{
|
|
@@ -134,7 +176,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
_databaseArr = [NSMutableArray new];
|
|
|
}
|
|
|
|
|
|
- //KWeakSelf
|
|
|
+ KWeakSelf
|
|
|
//dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
|
|
|
// NSLock *lock = [NSLock new];
|
|
|
// [lock lock];
|
|
@@ -167,6 +209,10 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
|
|
|
[lock unlock];
|
|
|
|
|
|
+ if(isReGet){
|
|
|
+ [self checkDownloadTaskFun];
|
|
|
+ }
|
|
|
+
|
|
|
complete(self->_databaseArr);
|
|
|
}];
|
|
|
// [lock unlock];
|
|
@@ -229,17 +275,12 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
|
|
|
|
|
|
//3.取消下载
|
|
|
- NSArray *allDownItemArr = [YCDownloadManager downloadList];
|
|
|
+ NSString *urlString = dataModel.fileUrl;
|
|
|
+ NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+
|
|
|
+ NSArray *allDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
|
|
|
for (YCDownloadItem *item in allDownItemArr) {
|
|
|
- //解码
|
|
|
- NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
-
|
|
|
- HLog(@"%@\n%@\n%@",urlString,dataModel.fileUrl);
|
|
|
-
|
|
|
- if([urlString isEqualToString:dataModel.fileUrl]){
|
|
|
- [YCDownloadManager stopDownloadWithItem:item];
|
|
|
- //break;
|
|
|
- }
|
|
|
+ [YCDownloadManager stopDownloadWithItem:item];
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -384,21 +425,41 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
}
|
|
|
|
|
|
[YCDownloadManager pauseAllDownloadTask];
|
|
|
- //[[SGDownloadManager shareManager] suspendAllDownloadTask];
|
|
|
-
|
|
|
}
|
|
|
- else if(dataModel && item){//暂停指定任务
|
|
|
- [YCDownloadManager pauseDownloadWithItem:item];
|
|
|
+ else if(dataModel){//暂停指定任务
|
|
|
+ NSString *urlString = dataModel.fileUrl;
|
|
|
+ NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+
|
|
|
+ if(item && [item.downloadURL isEqualToString:requestURLEncodedString]){
|
|
|
+ [YCDownloadManager pauseDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ NSArray *allDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
|
|
|
+
|
|
|
+ if(allDownItemArr.count == 1){
|
|
|
+ YCDownloadItem *item = allDownItemArr.firstObject;
|
|
|
+ [YCDownloadManager pauseDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for (YCDownloadItem *item in allDownItemArr) {
|
|
|
+ if (item.downloadStatus == YCDownloadStatusFinished) {//这里有问题
|
|
|
+ [YCDownloadManager stopDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ [YCDownloadManager pauseDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.修改状态
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
@@ -409,24 +470,45 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
|
|
|
#pragma mark 重新开始下载
|
|
|
- (void)reDownloadFileFunBy:(NSMutableArray*)arr withAll:(BOOL)isAllType withItem:(YCDownloadItem*)item
|
|
|
{
|
|
|
- //目前只允许一个下载 所以先暂停任务
|
|
|
- //[[SGDownloadManager shareManager] suspendAllDownloadTask];
|
|
|
-
|
|
|
+
|
|
|
if(isAllType){
|
|
|
- //[[SGDownloadManager shareManager] startAllDownloadTask];
|
|
|
[YCDownloadManager resumeAllDownloadTask];
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
- if (item) {
|
|
|
- [YCDownloadManager resumeDownloadWithItem:item];
|
|
|
+
|
|
|
+ ShareFileDataModel* dataModel = nil;
|
|
|
+ if(arr && arr.count > 0){
|
|
|
+ dataModel = arr.firstObject;
|
|
|
+ }else{
|
|
|
+ return;
|
|
|
}
|
|
|
+ NSString *urlString = dataModel.fileUrl;
|
|
|
+ NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
|
-// for (ShareFileDataModel*model in arr) {
|
|
|
-// model.downloadBoxStateType = downloadBoxStateDownloadloading;
|
|
|
-// [self reDownloadFileFunBy:model];
|
|
|
-// break;
|
|
|
-// }
|
|
|
+ if (item && [item.downloadURL isEqualToString:requestURLEncodedString]) {
|
|
|
+ [YCDownloadManager resumeDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ NSArray *allDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
|
|
|
+
|
|
|
+ if(allDownItemArr.count == 1){
|
|
|
+ YCDownloadItem *item = allDownItemArr.firstObject;
|
|
|
+ [YCDownloadManager resumeDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for (YCDownloadItem *item in allDownItemArr) {
|
|
|
+ if (item.downloadStatus != YCDownloadStatusFinished) {
|
|
|
+ [YCDownloadManager resumeDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ [YCDownloadManager stopDownloadWithItem:item];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|