소스 검색

1.多个下载任务

huangxiaodong 1 년 전
부모
커밋
86d3ea44d1

+ 28 - 14
创维盒子/双子星云手机/Class/Set/uploadFile/customDownloadManager/customDownloadManager.m

@@ -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 保存本地 通知外界

+ 1 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/boxDownloadFileManager.m

@@ -41,6 +41,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 {
     //[mixDownloadManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
     [customDownloadManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
+    [customDownloadManager shareManager].maxDownLoadCount = 2;
     
     [self delItemInDoneTaskFun];
 }