Explorar o código

1.新的下载代码暂存

huangxiaodong hai 11 meses
pai
achega
892dac4cb2

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

@@ -34,7 +34,7 @@
 
 - (NSMutableArray *)getAllOperation {
     NSMutableDictionary *allOperationDict = [mixDownloadCacheManager getDownloadList];
-//    HLog(@"%@---%@", allOperation,allOperation.allKeys);
+    //HLog(@"%@---%@", allOperationDict,allOperationDict.allKeys);
     NSMutableArray *allOperationArray = [NSMutableArray array];
     for (NSDictionary *dict in allOperationDict.allValues) {
         mixDownloadOperation *operation = [mixDownloadOperation mj_objectWithKeyValues:dict];

+ 17 - 8
创维盒子/双子星云手机/Class/Set/uploadFile/mixDownloadManager/mixDownloadQueue.m

@@ -22,7 +22,7 @@
 - (instancetype)init {
 
     if (self = [super init]) {
-        _maxCount = 3;
+        _maxCount = 1;
         [self registeNotification];
     }
     return self;
@@ -100,18 +100,21 @@
 - (void)operateDownloadWithUrl:(NSString *)url session:(NSURLSession *)session handle:(DownloadHandleType)handle {
     // 1、任务列表里取任务
     mixDownloadOperation *operation = [self operationWithUrl:url];
+    HLog(@"operation.dataTask 1:%@",operation.dataTask);
     
     // 2、本地plist文件里提取的任务
     if (!operation) {
         NSDictionary *dict = [mixDownloadCacheManager queryFileInfoWithUrl:url];
         operation = [mixDownloadOperation mj_objectWithKeyValues:dict];
     }
-
+    HLog(@"operation.dataTask 2:%@",operation.dataTask);
+    
     // 3、本地plist文件里提取的任务不存在dataTask
     if (!operation.dataTask && operation.currentSize != operation.totalSize) {
         operation.dataTask = [self.session mix_downloadDataTaskWithURLString:operation.url startSize:operation.currentSize];
         [self.operations addObject:operation];
     }
+    HLog(@"operation.dataTask 3:%@",operation.dataTask);
     
     if (operation) {
         
@@ -125,7 +128,7 @@
                     
                     case NSURLSessionTaskStateSuspended:
                         HLog(@"NSURLSessionTaskStateSuspended");
-                        operation.dataTask = [self.session mix_downloadDataTaskWithURLString:operation.url startSize:operation.currentSize];
+                        //operation.dataTask = [self.session mix_downloadDataTaskWithURLString:operation.url startSize:operation.currentSize];
                         break;
                         
                     case NSURLSessionTaskStateCanceling:
@@ -148,12 +151,17 @@
                     return;
                 }
                 
+                HLog(@"operation.dataTask resume:%@",operation.dataTask);
                 [operation.dataTask resume]; // 开始
                 [self operationStartWithOperation:operation];
                 break;
             case DownloadHandleTypeSuspend:
-                [operation.dataTask suspend]; // 暂停
+                HLog(@"operation.dataTask suspend:%@",operation.dataTask);
+                //[operation.dataTask suspend]; // 暂停
+                [operation.dataTask cancel]; // 暂停
                 [self operationSuspendWithOperation:operation];
+                //检测是否有等待下载的任务 有就开启下一个
+                [self taskExeEnd:nil];
                 break;
             case DownloadHandleTypeCancel:
                 if (operation.dataTask) { // 任务列表删除任务
@@ -176,7 +184,8 @@
             if (!operation.dataTask) { // 给plist里的任务添加dataTask 添加到operations
                 operation.dataTask = [self.session mix_downloadDataTaskWithURLString:operation.url startSize:operation.currentSize];
             }
-            [operation.dataTask suspend];
+            //[operation.dataTask suspend];
+            [operation.dataTask cancel];
             [self operationSuspendWithOperation:operation];
         }else {
             HLog(@"已完成的任务");
@@ -191,12 +200,12 @@
     [self.operations enumerateObjectsUsingBlock:^(mixDownloadOperation * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         
         mixDownloadOperation *operation = (mixDownloadOperation *)obj;
-        if (!operation.dataTask) { // 给plist里的任务添加dataTask 添加到operations
+        //if (!operation.dataTask) { // 给plist里的任务添加dataTask 添加到operations
             operation.dataTask = [self.session mix_downloadDataTaskWithURLString:operation.url startSize:operation.currentSize];
-        }
+        //}
   
         if ([self getOperationDoing].count < self.maxCount) { // 下载中任务数少于最大任务限制
-            
+            HLog(@"getOperationDoing %@",operation.fileName);
             switch (operation.dataTask.state) {
                 case NSURLSessionTaskStateRunning:
                     HLog(@"NSURLSessionTaskStateRunning");

+ 2 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/mixDownloadManager/mixDownloadSession.m

@@ -150,7 +150,8 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
         config.timeoutIntervalForResource = -1;
 //        config.TLSMaximumSupportedProtocol = kSSLProtocolAll;
         
-        _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue currentQueue]];
+        //_session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue currentQueue]];
+        _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
     }
     
     return _session;

+ 1 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/boxDownloadFileRecordCell.m

@@ -614,7 +614,7 @@
         
     }
     else if(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
-       
+        _fileSpeedlabel.text = @"";
         [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
     }
     

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

@@ -39,6 +39,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 
 - (void)initDownloadManagerFun
 {
+    [mixDownloadManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
     //[mixDownloadManager shareManager]
     
     [self delItemInDoneTaskFun];
@@ -315,12 +316,6 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             NSString *urlString = fileModel.fileUrl;
             NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 
-//            YCDownloadItem*item = [YCDownloadItem itemWithUrl:requestURLEncodedString fileId:fileModel.fileName];
-//            //item.extraData = [VideoListInfoModel dateWithInfoModel:model];
-//            [YCDownloadManager startDownloadWithItem:item];
-            
-            [mixDownloadManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
-            
             [[mixDownloadManager shareManager] downloadWithURL:[NSURL URLWithString:requestURLEncodedString] complete:^(NSDictionary * _Nonnull respose, NSError * _Nonnull error) {
                 HLog(@"download:%@",respose);
             }];