소스 검색

1.内网下载走http的初步调试通过

huangxiaodong 10 달 전
부모
커밋
89068b1e37

+ 40 - 8
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -230,6 +230,14 @@
 		6B21709D2B15CDB600656670 /* NSArray+Log.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B21709B2B15CDB600656670 /* NSArray+Log.m */; };
 		6B2170A02B15D39900656670 /* privacyModeTipViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B21709E2B15D39900656670 /* privacyModeTipViewController.h */; };
 		6B2170A12B15D39900656670 /* privacyModeTipViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B21709F2B15D39900656670 /* privacyModeTipViewController.m */; };
+		6B238C8E2C60AAE200C5AC2F /* nasDownloadManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B238C8D2C60AAE200C5AC2F /* nasDownloadManager.m */; };
+		6B238C8F2C60AAE200C5AC2F /* nasDownloadManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B238C8C2C60AAE200C5AC2F /* nasDownloadManager.h */; };
+		6B238C902C60AAE200C5AC2F /* nasDownloadManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B238C8C2C60AAE200C5AC2F /* nasDownloadManager.h */; };
+		6B238C912C60AAE200C5AC2F /* nasDownloadManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B238C8D2C60AAE200C5AC2F /* nasDownloadManager.m */; };
+		6B238C942C60AF6A00C5AC2F /* nasDownloadFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B238C932C60AF6A00C5AC2F /* nasDownloadFileManager.m */; };
+		6B238C952C60AF6A00C5AC2F /* nasDownloadFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B238C922C60AF6A00C5AC2F /* nasDownloadFileManager.h */; };
+		6B238C962C60AF6A00C5AC2F /* nasDownloadFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B238C922C60AF6A00C5AC2F /* nasDownloadFileManager.h */; };
+		6B238C972C60AF6A00C5AC2F /* nasDownloadFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B238C932C60AF6A00C5AC2F /* nasDownloadFileManager.m */; };
 		6B2C1E1C2C070ADE00FDCF82 /* ZFAVPlayerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B2C1DCC2C070ADE00FDCF82 /* ZFAVPlayerManager.h */; };
 		6B2C1E1D2C070ADE00FDCF82 /* ZFAVPlayerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B2C1DCC2C070ADE00FDCF82 /* ZFAVPlayerManager.h */; };
 		6B2C1E1E2C070ADE00FDCF82 /* ZFAVPlayerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B2C1DCD2C070ADE00FDCF82 /* ZFAVPlayerManager.m */; };
@@ -1590,6 +1598,10 @@
 		6B21709B2B15CDB600656670 /* NSArray+Log.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Log.m"; sourceTree = "<group>"; };
 		6B21709E2B15D39900656670 /* privacyModeTipViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = privacyModeTipViewController.h; sourceTree = "<group>"; };
 		6B21709F2B15D39900656670 /* privacyModeTipViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = privacyModeTipViewController.m; sourceTree = "<group>"; };
+		6B238C8C2C60AAE200C5AC2F /* nasDownloadManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = nasDownloadManager.h; sourceTree = "<group>"; };
+		6B238C8D2C60AAE200C5AC2F /* nasDownloadManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = nasDownloadManager.m; sourceTree = "<group>"; };
+		6B238C922C60AF6A00C5AC2F /* nasDownloadFileManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = nasDownloadFileManager.h; sourceTree = "<group>"; };
+		6B238C932C60AF6A00C5AC2F /* nasDownloadFileManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = nasDownloadFileManager.m; sourceTree = "<group>"; };
 		6B2C1DCC2C070ADE00FDCF82 /* ZFAVPlayerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFAVPlayerManager.h; sourceTree = "<group>"; };
 		6B2C1DCD2C070ADE00FDCF82 /* ZFAVPlayerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFAVPlayerManager.m; sourceTree = "<group>"; };
 		6B2C1DCF2C070ADE00FDCF82 /* UIImageView+ZFCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+ZFCache.h"; sourceTree = "<group>"; };
@@ -2699,6 +2711,17 @@
 			path = privacyMode;
 			sourceTree = "<group>";
 		};
+		6B238C8B2C60AA1B00C5AC2F /* nasDownloadManager */ = {
+			isa = PBXGroup;
+			children = (
+				6B238C8C2C60AAE200C5AC2F /* nasDownloadManager.h */,
+				6B238C8D2C60AAE200C5AC2F /* nasDownloadManager.m */,
+				6B238C922C60AF6A00C5AC2F /* nasDownloadFileManager.h */,
+				6B238C932C60AF6A00C5AC2F /* nasDownloadFileManager.m */,
+			);
+			path = nasDownloadManager;
+			sourceTree = "<group>";
+		};
 		6B2C1DCE2C070ADE00FDCF82 /* AVPlayer */ = {
 			isa = PBXGroup;
 			children = (
@@ -3052,6 +3075,7 @@
 		6B5D86632C227C4A008D25EA /* NAS */ = {
 			isa = PBXGroup;
 			children = (
+				6B238C8B2C60AA1B00C5AC2F /* nasDownloadManager */,
 				6B8A5ADD2C3BCB2700E40B19 /* recenFile */,
 				6BC741362C23C7BE0049BA8D /* model */,
 				6B5D866A2C22AE0B008D25EA /* view */,
@@ -3827,6 +3851,7 @@
 				18FCE53F2AD136670020F623 /* PlayerViewController+TouchPointXD.h in Headers */,
 				6B679DFE2C255DC900D0DC03 /* MineCommonUsedView.h in Headers */,
 				18FCE53E2AD136670020F623 /* PlayerViewController+AdjustBtnFrame.h in Headers */,
+				6B238C952C60AF6A00C5AC2F /* nasDownloadFileManager.h in Headers */,
 				6B7E043A2C3E6BBC004B4948 /* webSocketManager+downloadNasFile.h in Headers */,
 				6B5BE5812BFC81E300A1B9B3 /* NASFileAndFolderModel.h in Headers */,
 				6B7EA7BC2BF759AC002D5CC2 /* shareSecretTableViewCell.h in Headers */,
@@ -3920,6 +3945,7 @@
 				6BC7413A2C23C8870049BA8D /* cloudPhoneViewController.h in Headers */,
 				6B2C1E602C070ADE00FDCF82 /* ZFKVOController.h in Headers */,
 				6B0581A22AFCF50300D37290 /* AJPhotoListCell.h in Headers */,
+				6B238C8F2C60AAE200C5AC2F /* nasDownloadManager.h in Headers */,
 				6B3AD68A2BF4AE630096D6B7 /* backupsOptionViewController.h in Headers */,
 				6BC741462C24097E0049BA8D /* webSocketManager+baseDownload.h in Headers */,
 				187076772A9F400300F15F7F /* PlayerLoadingView.h in Headers */,
@@ -4092,6 +4118,7 @@
 				6BD506CA2B9576A4006E7CB0 /* PlayerViewController+TouchPointXD.h in Headers */,
 				6B679E002C255DC900D0DC03 /* MineCommonUsedView.h in Headers */,
 				6BD506CB2B9576A4006E7CB0 /* PlayerViewController+AdjustBtnFrame.h in Headers */,
+				6B238C962C60AF6A00C5AC2F /* nasDownloadFileManager.h in Headers */,
 				6B7E043D2C3E6BBC004B4948 /* webSocketManager+downloadNasFile.h in Headers */,
 				6B5BE5832BFC81E300A1B9B3 /* NASFileAndFolderModel.h in Headers */,
 				6B7EA7BE2BF759AC002D5CC2 /* shareSecretTableViewCell.h in Headers */,
@@ -4185,6 +4212,7 @@
 				6BC7413C2C23C8870049BA8D /* cloudPhoneViewController.h in Headers */,
 				6B2C1E612C070ADE00FDCF82 /* ZFKVOController.h in Headers */,
 				6BD506F32B9576A4006E7CB0 /* AJPhotoListCell.h in Headers */,
+				6B238C902C60AAE200C5AC2F /* nasDownloadManager.h in Headers */,
 				6B3AD68D2BF4AE630096D6B7 /* backupsOptionViewController.h in Headers */,
 				6BC741482C24097E0049BA8D /* webSocketManager+baseDownload.h in Headers */,
 				6BD506F42B9576A4006E7CB0 /* PlayerLoadingView.h in Headers */,
@@ -4811,6 +4839,7 @@
 				6B4C0F752C0314BA0070EF2E /* DFPlayerTool.m in Sources */,
 				6BD507712B9576A4006E7CB0 /* AFImageDownloader.m in Sources */,
 				6BD507722B9576A4006E7CB0 /* UIColor+HZXColor.m in Sources */,
+				6B238C912C60AAE200C5AC2F /* nasDownloadManager.m in Sources */,
 				6BD507732B9576A4006E7CB0 /* CalculatorViewController.m in Sources */,
 				6B5BE5942BFCA5FA00A1B9B3 /* videoPlayViewController.m in Sources */,
 				6B4C0F6D2C0314BA0070EF2E /* DFPlayerRequestManager.m in Sources */,
@@ -4935,6 +4964,7 @@
 				6BA08F4A2C01D05B00A2242D /* CWFileManager.m in Sources */,
 				6B6ABEE32BFF3DD000480BAC /* receiveHeadView.m in Sources */,
 				6BD507C52B9576A4006E7CB0 /* commandSendCheckModel.m in Sources */,
+				6B238C972C60AF6A00C5AC2F /* nasDownloadFileManager.m in Sources */,
 				6BD507C62B9576A4006E7CB0 /* GuideView.m in Sources */,
 				6BD507C72B9576A4006E7CB0 /* ShortcutManager.m in Sources */,
 				6BD507C82B9576A4006E7CB0 /* uploadFileRecordViewController.m in Sources */,
@@ -5158,6 +5188,7 @@
 				6B4C0F742C0314BA0070EF2E /* DFPlayerTool.m in Sources */,
 				183AE6532A8A2CF000B11CB0 /* AFImageDownloader.m in Sources */,
 				A003F6B327D841EE00715CBF /* UIColor+HZXColor.m in Sources */,
+				6B238C8E2C60AAE200C5AC2F /* nasDownloadManager.m in Sources */,
 				18E557222A3C5D75005CC84B /* CalculatorViewController.m in Sources */,
 				6B5BE5922BFCA5FA00A1B9B3 /* videoPlayViewController.m in Sources */,
 				6B4C0F6C2C0314BA0070EF2E /* DFPlayerRequestManager.m in Sources */,
@@ -5282,6 +5313,7 @@
 				6BA08F492C01D05B00A2242D /* CWFileManager.m in Sources */,
 				6B6ABEE12BFF3DD000480BAC /* receiveHeadView.m in Sources */,
 				6B1CC2CF2B6B6D6B00AD4217 /* commandSendCheckModel.m in Sources */,
+				6B238C942C60AF6A00C5AC2F /* nasDownloadFileManager.m in Sources */,
 				18963B472AB84398006E7C50 /* GuideView.m in Sources */,
 				18FCE5452AD136FF0020F623 /* ShortcutManager.m in Sources */,
 				6B0582812B01C67400D37290 /* uploadFileRecordViewController.m in Sources */,
@@ -5459,7 +5491,7 @@
 				CODE_SIGN_ENTITLEMENTS = "计算器.entitlements";
 				CODE_SIGN_IDENTITY = "Apple Development";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 13;
+				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
@@ -5520,7 +5552,7 @@
 					"$(PROJECT_DIR)/双子星云手机/Vendor/UDP/RayProxy",
 					"$(PROJECT_DIR)/RayProxy",
 				);
-				MARKETING_VERSION = 1.4.1;
+				MARKETING_VERSION = 1.4.2;
 				PRODUCT_BUNDLE_IDENTIFIER = com.armcloud.privacy.x.box;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";
@@ -5542,7 +5574,7 @@
 				CODE_SIGN_ENTITLEMENTS = "计算器.entitlements";
 				CODE_SIGN_IDENTITY = "Apple Development";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 13;
+				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
@@ -5603,7 +5635,7 @@
 					"$(PROJECT_DIR)/双子星云手机/Vendor/UDP/RayProxy",
 					"$(PROJECT_DIR)/RayProxy",
 				);
-				MARKETING_VERSION = 1.4.1;
+				MARKETING_VERSION = 1.4.2;
 				PRODUCT_BUNDLE_IDENTIFIER = com.armcloud.privacy.x.box;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";
@@ -5740,7 +5772,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 24;
+				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -5797,7 +5829,7 @@
 					"$(PROJECT_DIR)/双子星云手机/Vendor/UDP/RayProxy",
 					"$(PROJECT_DIR)/RayProxy",
 				);
-				MARKETING_VERSION = 1.4.1;
+				MARKETING_VERSION = 1.4.2;
 				PRODUCT_BUNDLE_IDENTIFIER = com.armcloud.privacy.x.box;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";
@@ -5821,7 +5853,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 24;
+				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -5878,7 +5910,7 @@
 					"$(PROJECT_DIR)/双子星云手机/Vendor/UDP/RayProxy",
 					"$(PROJECT_DIR)/RayProxy",
 				);
-				MARKETING_VERSION = 1.4.1;
+				MARKETING_VERSION = 1.4.2;
 				PRODUCT_BUNDLE_IDENTIFIER = com.armcloud.privacy.x.box;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";

+ 1 - 1
创维盒子/双子星云手机/AppDelegate/AppDelegate.h

@@ -32,7 +32,7 @@
 
 @property (nonatomic, strong) NASMsgModel * NASMsgMod;
 @property (nonatomic, copy) NSString * NASShareFileService;//走公网的
-@property (nonatomic, copy) NSString * NASFileByBoxService;//本盒子的IP
+@property (nonatomic, copy) NSString * NASFileByBoxService;//本盒子的IP 或者公网
 
 //与 isFirstInputPwdDone 有重复的地方 后续优化
 @property (nonatomic, assign)  BOOL isDidShowPwdType;// 是否显示密码界面了

+ 1 - 0
创维盒子/双子星云手机/AppDelegate/Config/Notification.h

@@ -139,6 +139,7 @@
 //#define NotLoadOtherDataFinished  @"loadOtherDataFinished"
 
 /* nas下载完成 通知*/
+#define nasShareDownloadTaskFinishedNotification                 @"nasShareDownloadTaskFinishedNot"
 #define nasDownloadTaskFinishedNotification                 @"nasDownloadTaskFinishedNot"
 
 /*获取推流页导航栏变化通知*/

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

@@ -31,7 +31,7 @@
         _selectModelArr = [NSMutableArray new];
         _curDataArr = [NSMutableArray new];
         
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskFinishedNotification object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasShareDownloadTaskFinishedNotification object:nil];
         
     }
     return self;

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

@@ -357,7 +357,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     }
     
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
+        [[NSNotificationCenter defaultCenter] postNotificationName:nasShareDownloadTaskFinishedNotification object:model];
         
         [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
     });
@@ -644,7 +644,6 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             }
             else{//存在 通知保存流程
                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-                    //[[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
                     [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
                 });
                 break;

+ 1 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileRecordViewController.h

@@ -10,6 +10,7 @@
 #import "TZAssetModel+imageData.h"
 #import "downloadThumbnailManager.h"
 #import "uploadImageOrVideoViewController.h"
+#import "nasDownloadFileManager.h"
 
 NS_ASSUME_NONNULL_BEGIN
 

+ 41 - 24
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileRecordViewController.m

@@ -18,7 +18,7 @@
 #import "backupsFilerecordTableView.h"
 #import "backupsFileManager.h"
 #import "photosBackupsTaskModel.h"
-#import "downloadManager.h"
+//#import "downloadManager.h"
 #import "downloadFileRecordTableView.h"
 #import "MySetViewController.h"
 #import "receiveView.h"
@@ -74,6 +74,7 @@
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadFileRefreshFun:)  name:downloadFileRefreshNotification  object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadFileSuspendAllFun:)  name:downloadFileSuspendAllNotification  object:nil];
     
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskFinishedNotification object:nil];
     
     [self.view setBackgroundColor:[UIColor whiteColor]];
     
@@ -123,7 +124,7 @@
     }
     
     //检测是否还有没保存的任务
-    [[downloadManager shareInstance] checkDownloadDonePlistInfoFun];
+    [[nasDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
     
     [self getBackupsDatabaseFun];
     
@@ -587,7 +588,7 @@
 - (void)getDownloadDataInDatabaseFun:(BOOL)isRegetType
 {
     KWeakSelf
-    [[downloadManager shareInstance] getDataInDatabaseFun:isRegetType complete:^(NSMutableArray * _Nonnull Arr) {
+    [[nasDownloadFileManager shareInstance] getDataInDatabaseFun:isRegetType complete:^(NSMutableArray * _Nonnull Arr) {
       
         weakSelf.didGetDownloadDataType = YES;
         [weakSelf handleRemoveIndicator];
@@ -599,7 +600,7 @@
         
         NSMutableArray *curLoadIngArr = Arr[0];
         //不是上传视频和进来的  所以上传状态(上传中和等待)改为暂停
-        if(![downloadManager shareInstance].isDownloadIngType){
+        if(![nasDownloadManager shareManager].isDownLoadIngType){
 //            for (couldPhoneFileModel * curModel in curLoadIngArr) {
 //                curModel.curDownloadStateType = downloadStateSuspend;
 //            }
@@ -614,7 +615,7 @@
             }
             
             if(handleDownloadArr.count >0){
-                [[downloadManager shareInstance] reDownloadFileFunBy:handleDownloadArr withAll:YES];
+                [[nasDownloadFileManager shareInstance] reDownloadFileFunBy:handleDownloadArr withAll:NO];
             }
         }
         
@@ -624,17 +625,6 @@
             [weakSelf handleDownloadingRightButFun];
         });
         
-        //检测下预览图片是否都下载
-//        if(isRegetType){
-//            if(Arr &&Arr.count == 3){
-//                NSArray *downingArr = Arr[0];
-//                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-//                    [[downloadThumbnailManager shareInstance] handlToDownloadThumbnailInDownTableViewWith:downingArr];
-//                });
-//            }
-//
-//        }
-        
     }];
     
 }
@@ -670,13 +660,13 @@
         //不处理
     }
     else{
-        NSMutableArray *upLoadingArr = [downloadManager shareInstance].downLoadFileModelDataArr;
-        BOOL isDownloadIngType = [downloadManager shareInstance].isDownloadIngType;
+        NSMutableArray *downloadingArr = [nasDownloadFileManager shareInstance].downLoadFileModelDataArr;
+        BOOL isDownloadIngType = [nasDownloadManager shareManager].isDownLoadIngType;
 
-        if(!upLoadingArr ||upLoadingArr.count == 0 || !isDownloadIngType){//不是下载状态
+        if(!downloadingArr ||downloadingArr.count == 0 || !isDownloadIngType){//不是下载状态
             _midTableView.downloadingHeadView.rightButton.selected = YES;
         }
-        else if(upLoadingArr.count == _midTableView.downloadingArr.count){
+        else if(downloadingArr.count == _midTableView.downloadingArr.count){
             _midTableView.downloadingHeadView.rightButton.selected = NO;
         }
         else{
@@ -1079,8 +1069,7 @@
 -(void)gotoDownloadFile:(NSMutableArray*)selectedItems
 {
     KWeakSelf
-    [[downloadManager shareInstance] handleCouldPhoneFileModelToDownloadFileDataFunBy:selectedItems complete:^(NSMutableArray * _Nonnull Arr) {
-        
+    [[nasDownloadFileManager shareInstance] addNasDownloadRecordFunBy:selectedItems complete:^(NSMutableArray * _Nonnull Arr) {
         weakSelf.didGetDownloadDataType = YES;
         [weakSelf handleRemoveIndicator];
   
@@ -1098,6 +1087,25 @@
         });
     }];
     
+//    [[downloadManager shareInstance] handleCouldPhoneFileModelToDownloadFileDataFunBy:selectedItems complete:^(NSMutableArray * _Nonnull Arr) {
+//        
+//        weakSelf.didGetDownloadDataType = YES;
+//        [weakSelf handleRemoveIndicator];
+//  
+//        if(!Arr ||Arr.count != 3){
+//            HLog(@"数据库出错\n\n\n");
+//            return;
+//        }
+//        
+//        //NSMutableArray *curLoadIngArr = Arr[0];
+//        
+//        mainBlock(^{
+//            weakSelf.midTableView.outSideDataArr = Arr;
+//            [weakSelf.midTableView reloadDataFun];
+//            //[weakSelf handleUploadingRightButFun];
+//        });
+//    }];
+    
     //处理数据埋点
     NSString * firstFileType = nil;
     BOOL isSameFileType = YES;
@@ -1133,6 +1141,15 @@
     }
 }
 
+#pragma mark nas http下载完成
+- (void)downloadTaskFinishedNoti:(NSNotification *)notification
+{
+    customDownloadOperation *model = notification.object;
+    NSString *url = model.url;
+    
+    [self getDownloadDataInDatabaseFun:NO];
+}
+
 - (void)downloadFileRefreshFun:(NSNotification*)not
 {
     couldPhoneFileModel *downloadTaskMod = [not object];
@@ -1195,11 +1212,11 @@
     _midTableView.downloadingHeadView.rightButton.selected = !_midTableView.downloadingHeadView.rightButton.selected;
     
     if(_midTableView.downloadingHeadView.rightButton.selected){
-        [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
+        [[nasDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
     }
     else{
         NSMutableArray *leftArr = _midTableView.downloadingArr;
-        [[downloadManager shareInstance] reDownloadFileFunBy:leftArr withAll:YES];
+        [[nasDownloadFileManager shareInstance] reDownloadFileFunBy:leftArr withAll:YES];
     }
 }
 

+ 154 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileView/downloadFileRecordCell.m

@@ -10,6 +10,7 @@
 #import "cachesFileManager.h"
 #import <SDWebImage/SDWebImage.h>
 #import "downloadThumbnailManager.h"
+#import "nasDownloadManager.h"
 
 @interface downloadFileRecordCell ()
 @property(nonatomic,strong) UIImageView *fileImageView;
@@ -34,6 +35,8 @@
     
     if (self)
     {
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:nasDownloadTaskExeing object:nil];
+        
         [self drawView];
     }
     
@@ -424,5 +427,156 @@
     });
 }
 
+#pragma mark 下载通知
+- (void)downloadTaskDownloadingNoti:(NSNotification *)notification
+{
+    
+    if(_curCouldPhoneFileModel.curDownloadStateType != downloadStateWait
+       && _curCouldPhoneFileModel.curDownloadStateType != downloadStateUploading){
+        return;
+    }
+    
+    customDownloadOperation *model = notification.userInfo.allValues.firstObject;
+    if(!model)return;
+    
+    if (model.downloadState != customDownloadStateDoing) {
+        return;
+    }
+    mainBlock(^{
+        [self downloadItem:model downloadedSize:model.currentSize totalSize:model.totalSize];
+    });
+}
+
+
+- (void)downloadItem:(customDownloadOperation *)model downloadedSize:(int64_t)downloadedSize totalSize:(int64_t)totalSize {
+    
+    //解码
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    HLog(@"下载中:%lld --- %lld \n%@\n%@",downloadedSize,totalSize,urlString,_curCouldPhoneFileModel.fileUrl);
+    
+    if(_curCouldPhoneFileModel
+       &&(_curCouldPhoneFileModel.curDownloadStateType != downloadStateWait
+          &&_curCouldPhoneFileModel.curDownloadStateType != downloadStateUploading)
+       ){
+        HLog(@"当前状态 -- %u",_curCouldPhoneFileModel.curDownloadStateType);
+        return;
+    }
+    
+    if (![urlString isEqualToString:_curCouldPhoneFileModel.fileUrl]
+        ||downloadedSize == totalSize) { // 不是这一个任务
+        return;
+    }
+
+    _curCouldPhoneFileModel.curDownloadStateType = downloadStateUploading;
+    _curCouldPhoneFileModel.didDownloadBytes = downloadedSize;
+    _curCouldPhoneFileModel.curTimeInterval = [[NSDate date] timeIntervalSince1970];
+    
+    KWeakSelf
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+        [weakSelf updateDataDownloadingBy:_curCouldPhoneFileModel];
+    });
+}
+
+//下载中最更进度
+- (void)updateDataDownloadingBy:(couldPhoneFileModel*)couldPhoneFileMod{
+    
+    if(_curCouldPhoneFileModel
+       &&(_curCouldPhoneFileModel.curDownloadStateType == downloadStateDone
+       ||_curCouldPhoneFileModel.curTimeInterval == downloadStateFail)
+       ){
+        return;
+    }
+    NSString * speedStr = nil;
+    //进度设置
+    CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
+    
+    NSInteger totalSize = couldPhoneFileMod.length;
+    if(totalSize == 0.0){
+        totalSize += 0.0001;
+    }
+    
+    CGFloat curProgress = couldPhoneFileMod.didDownloadBytes/(totalSize*1.0);
+    
+    if(curProgress > 1){
+        curProgress = 1;
+    }
+    
+    frame.size.width =  frame.size.width * curProgress;
+    
+    if (isnan(frame.size.width))
+    {
+        HLog(@"计算出错了");
+        frame.size.width = 10.0;
+    }
+    
+    _progressSelectView.frame = frame;
+    //_glayer.frame = frame;
+    
+    NSString * totalSizeStr = nil;
+    NSInteger totalSize_k = totalSize / 1024;
+    if(totalSize_k < 1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
+    }
+    else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
+        
+    }
+    else{
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
+    }
+    
+    NSString * didUploadStr = nil;
+    NSInteger didUploadSize_k = couldPhoneFileMod.didDownloadBytes / 1024;
+    if(didUploadSize_k < 1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
+    }
+    else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
+        
+    }
+    else{
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
+    }
+    
+    _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
+
+    if(couldPhoneFileMod.curDownloadStateType == downloadStateUploading){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
+        _fileSpeedlabel.hidden = NO;
+    
+        if(couldPhoneFileMod.preTimeInterval <= 0
+           || couldPhoneFileMod.didDownloadBytes == couldPhoneFileMod.preDownloadBytes){
+            //_fileSpeedlabel.text = @"--";
+        }
+        else{
+            NSTimeInterval  timers = couldPhoneFileMod.curTimeInterval - couldPhoneFileMod.preTimeInterval;
+            
+            if(timers > 0){
+                //long speed= 1*1024*1024 / timers;
+                
+                long speed= (couldPhoneFileMod.didDownloadBytes - couldPhoneFileMod.preDownloadBytes) / timers;
+                
+                
+                NSInteger speed_k = speed / (1024);
+                if(speed_k < 1024){
+                    speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
+                }
+                else {
+                    speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
+                }
+                
+                //HLog(@"22211:%@",_fileSpeedlabel.description);
+            }
+        }
+        
+        couldPhoneFileMod.preTimeInterval = couldPhoneFileMod.curTimeInterval;
+        couldPhoneFileMod.preDownloadBytes = couldPhoneFileMod.didDownloadBytes;
+    }
+
+    if (speedStr) {
+        self->_fileSpeedlabel.text = speedStr;
+    }
+}
+
 @end
 

+ 2 - 0
创维盒子/双子星云手机/CloudPlayer/Model/couldPhoneFileListModel.h

@@ -48,6 +48,8 @@ typedef enum{
 
 @property (nonatomic, assign) NSTimeInterval  preTimeInterval;//计算速度用
 @property (nonatomic, assign) NSTimeInterval  curTimeInterval;//计算速度用
+@property (nonatomic, copy) NSString * fileUrl;
+@property (nonatomic, copy) NSString * failMsg;
 
 - (NSString*)getFileNameFun;
 

+ 7 - 0
创维盒子/双子星云手机/CloudPlayer/Model/couldPhoneFileListModel.m

@@ -13,6 +13,13 @@
     return [[NSString alloc] initWithFormat:@"%ld_%@",self.length,self.name];
 }
 
+- (NSString*)fileUrl
+{
+    NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
+    NSString *curFileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,self.path];
+    return curFileUrl;
+}
+
 #pragma mark - get download info
 // 构造回调信息
 - (NSDictionary *)downLoadInfoWithFinished:(BOOL)finished {

+ 64 - 0
创维盒子/双子星云手机/NAS/nasDownloadManager/nasDownloadFileManager.h

@@ -0,0 +1,64 @@
+//
+//  nasDownloadFileManager.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/8/5.
+//
+
+#import <Foundation/Foundation.h>
+#import "queryOneShareModel.h"
+#import "nasDownloadManager.h"
+#import "customDownloadCacheManager.h"
+//#import "uploadFileManager.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+//【IOS端】音频进行下载,下载列表提示下载到文件里,查看部分文件未成功下载到文件里
+//问题原因:在下载音频类(即是要保存到文件app的)文件--- UIDocumentPickerViewController 弹出来后不再处理下一个 意味着快速下载完几个任务 在完成后只能保存到一个到文件 其他的因为任务完成了 不再处理保存流程
+//解决方案:创建本地持久化 每次收到下载完成通知:
+//1.先做数据保存
+//2.然后再处理文件保存流程
+//3.删除此次保存数据
+//4.UIDocumentPickerViewController 保存后访问本地持久化 查询还有没有没处理的任务
+
+#define nas_box_download_tableName [[NSString alloc] initWithFormat:@"download_tableName_%@",[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn]
+
+@interface nasDownloadFileManager : NSObject
++(nasDownloadFileManager *)shareInstance;
+
+//数据库数据
+@property (nonatomic, strong) NSMutableArray * _Nullable databaseArr;
+@property (nonatomic, strong) NSMutableArray * _Nullable downLoadFileModelDataArr;
+@property (nonatomic, assign) BOOL  isFirstAutoStartType;//启动第一次需要重新开启
+
+@property (nonatomic, strong) NSMutableDictionary * _Nullable downloadDoneList;
+
+//添加保存记录 NSArray<couldPhoneFileModel>* fileListVOS;
+- (void)addNasDownloadRecordFunBy:(NSArray*)arr complete:(custom_complete_Arr)complete;
+#pragma mark 读取数据库数据
+- (void)getDataInDatabaseFun:(BOOL)isReGet complete:(custom_complete_Arr)complete;
+
+#pragma mark 删除本地数据库记录
+- (void)deleteBoxSaveFileRecordBy:(NSMutableArray *)delArr;
+
+#pragma mark 更新本地数据库记录
+- (void)updataBoxSaveDataInFailBy:(couldPhoneFileModel*)dataModel;
+
+#pragma mark 开始下载文件 couldPhoneFileModel
+- (void)beginDownloadFilesByUrls:(NSArray *)urlArr;
+
+#pragma mark 全部暂停 或者暂停某一个
+- (void)suspendDownloadFileFun:(BOOL)isSuspendAll withModel:(couldPhoneFileModel*)dataModel;
+#pragma mark 重新开始下载 arr 目前只支持一个的情况
+- (void)reDownloadFileFunBy:(NSMutableArray*)arr withAll:(BOOL)isAllType;
+#pragma mark 重新开始下载 第一次进去传输列表是用
+- (void)firstReDownloadAllFileFun;
+
+#pragma mark-保存完成后 删除此次信息 download done plist
+- (void)deleteDownloadDonePlistInfoBy:(NSString*)fullPath;
+
+#pragma mark-查询还有没有没处理的任务
+- (void)checkDownloadDonePlistInfoFun;
+@end
+
+NS_ASSUME_NONNULL_END

+ 659 - 0
创维盒子/双子星云手机/NAS/nasDownloadManager/nasDownloadFileManager.m

@@ -0,0 +1,659 @@
+//
+//  nasDownloadFileManager.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/8/5.
+//
+
+#import "nasDownloadFileManager.h"
+
+@implementation nasDownloadFileManager
+static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
++(nasDownloadFileManager *)shareInstance;
+{
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        cur_nasDownloadFileManager = [[nasDownloadFileManager alloc] init];
+        
+    });
+    
+    return cur_nasDownloadFileManager;
+}
+
+- (id)init
+{
+    self = [super init];
+    
+    if (self) {
+        //[self initManager];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskExeEnd object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskExeError object:nil];
+        
+        [self initDownloadManagerFun];
+    }
+    
+    return self;
+}
+
+- (void)initDownloadManagerFun
+{
+    [nasDownloadManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
+    [nasDownloadManager shareManager].maxDownLoadCount = 2;
+    
+    [self delItemInDoneTaskFun];
+}
+
+- (NSMutableArray*)downLoadFileModelDataArr
+{
+    if(_databaseArr && _databaseArr.count >=3){
+        return _databaseArr[0];
+    }
+    
+    return [NSMutableArray new];
+}
+#pragma mark 删除已经完成和删除文件的任务
+- (void)delItemInDoneTaskFun
+{
+//    NSArray *allDownItemArr = [YCDownloadManager downloadList];
+//
+//    for (YCDownloadItem *item in allDownItemArr) {
+//        if (item.downloadStatus == YCDownloadStatusFinished) {
+//            NSString *savePath =  item.savePath;
+//
+//            if (![[NSFileManager defaultManager] fileExistsAtPath:savePath]){
+//                [YCDownloadManager stopDownloadWithItem:item];
+//            }
+//        }
+//    }
+}
+
+#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 (couldPhoneFileModel*dataModel in downloadingArr) {
+//                if([urlString isEqualToString:dataModel.fileUrl]){
+//                    isNeedStopType = NO;
+//                }
+//            }
+//        }
+//
+//        if(downloadingFail && downloadingFail.count > 0){
+//            for (couldPhoneFileModel*dataModel in downloadingFail) {
+//                if([urlString isEqualToString:dataModel.fileUrl]){
+//                    if(item.downloadedSize >0){
+//                        isNeedStopType = NO;
+//                    }
+//                }
+//            }
+//        }
+//
+//        if(isNeedStopType){
+//            HLog(@"停止多的下载任务:%@",item.downloadURL);
+//            [YCDownloadManager stopDownloadWithItem:item];
+//        }
+//
+//    }
+}
+
+//添加保存记录
+- (void)addNasDownloadRecordFunBy:(NSArray*)arr complete:(custom_complete_Arr)complete{
+    if(arr && arr.count >0 ){
+        //1.排重处理
+        [self getDataInDatabaseFun:NO complete:^(NSMutableArray * _Nonnull Arr) {
+            [self filterDownloadingTaskFunWithNewTaskArr:arr complete:complete];
+        }];
+    }
+}
+
+- (void)filterDownloadingTaskFunWithNewTaskArr:(NSArray*)taskArr complete:(custom_complete_Arr)complete
+{
+    NSMutableArray *addTaskArr = [NSMutableArray new];
+    
+    NSMutableArray * downloadingArr = [NSMutableArray new];
+    if(_databaseArr && _databaseArr.count == 3){
+        downloadingArr = _databaseArr[0];
+    }
+    
+    
+    for (couldPhoneFileModel*model in taskArr) {
+        BOOL canAdd = YES;
+        
+        if(downloadingArr.count > 0){
+            for (couldPhoneFileModel*downloadingModel in downloadingArr) {
+                if([downloadingModel.fileUrl isEqualToString:model.fileUrl]){
+                    canAdd = NO;
+                    break;
+                }
+            }
+        }
+        
+        if(canAdd){
+            model.bg_tableName = nas_box_download_tableName;
+            [addTaskArr addObject:model];
+        }
+    }
+    
+    if(addTaskArr.count >0){
+        KWeakSelf
+        //[couldPhoneFileModel bg_saveOrUpdateArray:arr];
+        [couldPhoneFileModel bg_saveOrUpdateArrayAsync:addTaskArr complete:^(BOOL isSuccess) {
+            //保存完成重新读取数据库 这样下载中的任务才会完整
+            [weakSelf getDataInDatabaseFun:YES complete:^(NSMutableArray * _Nonnull Arr) {
+                [weakSelf beginDownloadFilesByUrls:addTaskArr];
+                complete(weakSelf.databaseArr);
+            }];
+            
+        }];
+    }
+    else{//任务下载中
+        complete(_databaseArr);
+    }
+}
+
+#pragma mark 读取数据库数据
+- (void)getDataInDatabaseFun:(BOOL)isReGet complete:(custom_complete_Arr)complete
+{
+    if(_databaseArr && _databaseArr.count == 3 && !isReGet){
+        complete(_databaseArr);
+        return;
+    }
+    
+    if(!_databaseArr)
+    {
+        _databaseArr = [NSMutableArray new];
+    }
+    
+    KWeakSelf
+    //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
+//    NSLock *lock = [NSLock new];
+//    [lock lock];
+        [couldPhoneFileModel bg_findAsync:nas_box_download_tableName limit:0 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
+            NSMutableArray *failArr = [NSMutableArray new];
+            NSMutableArray *doneArr = [NSMutableArray new];
+            NSMutableArray *otherArr = [NSMutableArray new];
+            if(array && array.count >0){
+                for (couldPhoneFileModel * curModel in array) {
+                    
+                    if(curModel.curDownloadStateType == downloadStateFail){
+                        [failArr addObject:curModel];
+                    }
+                    else if(curModel.curDownloadStateType == downloadStateDone){
+                        [doneArr addObject:curModel];
+                    }
+                    else{
+                        [otherArr addObject:curModel];
+                    }
+                }
+            }
+            NSLock *lock = [NSLock new];
+            [lock lock];
+            
+            NSMutableArray *newArr = [NSMutableArray new];
+            [newArr addObject:otherArr];
+            [newArr addObject:doneArr];
+            [newArr addObject:failArr];
+            self->_databaseArr = newArr;
+            
+            [lock unlock];
+            
+            if(isReGet){
+                [self checkDownloadTaskFun];
+            }
+            
+            complete(self->_databaseArr);
+        }];
+   // [lock unlock];
+    //});
+
+}
+
+- (void)handleDatabaseArrByDelete:(couldPhoneFileModel*)delModel
+{
+    if(_databaseArr && _databaseArr.count == 3 ){
+        
+        if(delModel.curDownloadStateType == downloadStateDone)
+        {
+            NSMutableArray *arr = _databaseArr[1];
+            [self deteleModel:delModel inArr:arr];
+        }
+        else if(delModel.curDownloadStateType == downloadStateFail){
+            NSMutableArray *arr = _databaseArr[2];
+            [self deteleModel:delModel inArr:arr];
+        }
+        else{
+            NSMutableArray *arr = _databaseArr[0];
+            [self deteleModel:delModel inArr:arr];
+        }
+    }
+}
+
+#pragma mark  处理删除内存数据
+- (void)deteleModel:(couldPhoneFileModel*)delModel inArr:(NSMutableArray*)delArr{
+    
+    for (couldPhoneFileModel *dataModel in delArr) {
+        if(delModel.bg_id.integerValue == dataModel.bg_id.integerValue){
+            [delArr removeObject:dataModel];
+            break;
+        }
+    }
+    
+}
+
+#pragma mark 删除本地数据库记录
+- (void)deleteBoxSaveFileRecordBy:(NSMutableArray *)delArr{
+  
+    NSMutableArray *curDelArr = [NSMutableArray arrayWithArray:delArr];
+    for (couldPhoneFileModel *dataModel in curDelArr) {
+        
+        //1.内存数据删除
+        [self handleDatabaseArrByDelete:dataModel];
+        
+        //2.删除数据量
+        NSMutableString* where = [[NSMutableString alloc] initWithString:@"where "];
+        
+        NSString *curStr =  [NSString stringWithFormat:@"%@=%@ ",bg_sqlKey(@"bg_id"),bg_sqlValue(dataModel.bg_id)];
+        [where appendString:curStr];
+        
+        [couldPhoneFileModel bg_deleteAsync:nas_box_download_tableName where:where complete:^(BOOL isSuccess) {
+            if(isSuccess){
+                
+            }
+        }];
+        
+        
+        //3.取消下载
+        NSString *urlString = dataModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        
+        [[nasDownloadManager shareManager] deleteDownloadWithUrl:requestURLEncodedString];
+    }
+    
+}
+
+
+#pragma mark 更新本地数据库记录
+- (void)updataBoxSaveDataInFailBy:(couldPhoneFileModel*)dataModel
+{
+    
+    //1.修改数据库
+    if(_databaseArr.count == 3){
+        NSMutableArray *failArr = _databaseArr[2];
+        NSMutableArray *ingArr = _databaseArr[0];
+        for (couldPhoneFileModel* model in failArr) {
+            if (dataModel.bg_id.integerValue == model.bg_id.integerValue) {
+                [failArr removeObject:model];
+                [ingArr addObject:dataModel];
+                break;
+            }
+        }
+    }
+   
+    [dataModel bg_saveOrUpdateAsync:^(BOOL isSuccess) {
+            
+    }];
+}
+
+#pragma mark 开始下载文件
+- (void)beginDownloadFilesByUrls:(NSArray *)urlArr{
+    
+//    NSMutableArray*arr =  [[SGDownloadManager shareManager] getAllOperation];
+//    if(arr && arr.count > 0){
+//        HLog(@"有任务正在下载");
+//        [[SGDownloadManager shareManager] startAllDownloadTask];
+//        return;
+//    }
+    
+    if(urlArr && urlArr.count > 0){
+        NSMutableArray *URLEncodedStringArr = [NSMutableArray new];
+        
+        for (NSInteger i= urlArr.count-1; i>=0; i--) {
+            couldPhoneFileModel *fileModel = urlArr[i];
+            
+            NSString *urlString = fileModel.fileUrl;
+            NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+//            [[mixDownloadManager shareManager] downloadWithURL:[NSURL URLWithString:requestURLEncodedString] complete:^(NSDictionary * _Nonnull respose, NSError * _Nonnull error) {
+//                HLog(@"download:%@",respose);
+//            }];
+            
+            [URLEncodedStringArr addObject:requestURLEncodedString];
+        }
+        
+        [[nasDownloadManager shareManager] addDownloadWithURLs:URLEncodedStringArr];
+        
+    }
+}
+
+#pragma mark 下载完成
+- (void)downloadTaskFinishedNoti:(NSNotification *)notification
+{
+    customDownloadOperation *model = notification.userInfo.allValues.firstObject;
+
+    if(!model)return;
+    
+    if (model.downloadState == customDownloadStateCompleted) {
+        
+        //1.先做数据保存
+        NSDictionary *dataDict = [model downLoadInfoWithFinished:YES];
+        [self saveFileInfoWithDict:dataDict with:model.url];
+        
+        [self handldDownloadDoneDataBy:model];
+    }
+    else if (model.downloadState == customDownloadStateFailed){
+        [self handldDownloadFailDataBy:model];
+    }
+    
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+        [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
+        
+        [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
+    });
+}
+
+
+
+#pragma mark 下载完成数据回调处理
+- (void)handldDownloadDoneDataBy:(customDownloadOperation*)model
+{
+    //解码
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+    if(_databaseArr && _databaseArr.count == 3 ){
+        NSMutableArray *ingArr = _databaseArr[0];
+        for (couldPhoneFileModel*dataModel in ingArr) {
+            HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
+            if([urlString isEqualToString:dataModel.fileUrl]){
+        
+                dataModel.curDownloadStateType = downloadStateDone;
+                
+                NSMutableArray *doneArr = _databaseArr[1];
+                [doneArr insertObject:dataModel atIndex:0];
+                
+                //更新数据库
+                [dataModel bg_saveOrUpdateAsync:^(BOOL isSuccess) {
+                                    
+                }];
+                
+                [self deteleModel:dataModel inArr:ingArr];
+                
+                break;
+            }
+        }
+    }
+
+}
+
+
+#pragma mark 下载失败数据回调处理
+- (void)handldDownloadFailDataBy:(customDownloadOperation*)model
+{
+    //解码
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+    if(_databaseArr && _databaseArr.count == 3 ){
+        NSMutableArray *ingArr = _databaseArr[0];
+        HLog(@"%@",ingArr)
+        for (couldPhoneFileModel*dataModel in ingArr) {
+            HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
+            if([urlString isEqualToString:dataModel.fileUrl]){
+                
+                dataModel.curDownloadStateType = downloadStateFail;
+                dataModel.failMsg = NSLocalizedString(@"File_download_error_404",nil);
+                
+                //失败里面添加
+                NSMutableArray *failArr = _databaseArr[2];
+                [failArr insertObject:dataModel atIndex:0];
+                
+                //更新数据库
+                [dataModel bg_saveOrUpdateAsync:^(BOOL isSuccess) {
+                                    
+                }];
+                
+                [self deteleModel:dataModel inArr:ingArr];
+                break;
+            }
+        }
+    }
+
+}
+
+#pragma mark 全部暂停 或者暂停某一个
+- (void)suspendDownloadFileFun:(BOOL)isSuspendAll withModel:(couldPhoneFileModel*)dataModel
+{
+    if(isSuspendAll){//全部暂停
+        
+        if (_databaseArr && _databaseArr.count == 3) {
+            NSMutableArray *downloadingArr = _databaseArr[0];
+            for (couldPhoneFileModel*model in downloadingArr) {
+                model.curDownloadStateType = downloadStateSuspend;
+            }
+            
+            if(downloadingArr.count > 0){
+                [couldPhoneFileModel bg_saveOrUpdateArrayAsync:downloadingArr complete:^(BOOL isSuccess) {
+                    
+                }];
+            }
+        }
+        
+        [[nasDownloadManager shareManager] suspendAllDownloadTask];
+    }
+    else if(dataModel){//暂停指定任务
+        NSString *urlString = dataModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        HLog(@"%@",urlString);
+        
+        [[nasDownloadManager shareManager] supendDownloadWithUrl:requestURLEncodedString];
+        
+        //2.修改状态
+        if (_databaseArr && _databaseArr.count == 3) {
+            NSMutableArray *downloadingArr = _databaseArr[0];
+            for (couldPhoneFileModel*model in downloadingArr) {
+                
+                if(model.bg_id.integerValue == dataModel.bg_id.integerValue){
+                    model.curDownloadStateType = downloadStateSuspend;
+                    break;
+                }
+            }
+            if(downloadingArr.count > 0){
+                [couldPhoneFileModel bg_saveOrUpdateArrayAsync:downloadingArr complete:^(BOOL isSuccess) {
+                    
+                }];
+            }
+        }
+    }
+}
+
+#pragma mark 重新开始下载
+- (void)reDownloadFileFunBy:(NSMutableArray*)arr withAll:(BOOL)isAllType
+{
+ 
+    if(isAllType){
+        //[[mixDownloadManager shareManager] startAllDownloadTask];
+
+        if (_databaseArr && _databaseArr.count == 3) {
+        
+            NSMutableArray *downloadingArr = _databaseArr[0];
+            NSMutableArray *ReverseOrderArr = [NSMutableArray new];
+            
+            for (NSInteger i = downloadingArr.count -1; i>=0; i--) {
+                couldPhoneFileModel*model = downloadingArr[i];
+                model.curDownloadStateType = downloadStateUploading;
+                [ReverseOrderArr addObject:model];
+            }
+            
+//            for (couldPhoneFileModel*model in downloadingArr) {
+//                model.downloadBoxStateType = downloadBoxStateDownloadloading;
+//            }
+            
+            //这里处理重新下载
+            [self beginDownloadFilesByUrls:ReverseOrderArr];
+            
+            
+            if(downloadingArr.count > 0){
+                [couldPhoneFileModel bg_updateArrayAsync:downloadingArr complete:^(BOOL isSuccess) {
+                                
+                }];
+            }
+        }
+    }
+    else{
+        
+        couldPhoneFileModel* dataModel = nil;
+        if(arr && arr.count > 0){
+            dataModel = arr.firstObject;
+            
+            //修改数据库状态
+            dataModel.curDownloadStateType = downloadStateUploading;
+            [couldPhoneFileModel bg_saveOrUpdateArrayAsync:@[dataModel] complete:^(BOOL isSuccess) {
+                            
+            }];
+        }else{
+            return;
+        }
+        NSString *urlString = dataModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        HLog(@"%@",urlString);
+        
+        [[nasDownloadManager shareManager] startDownLoadWithUrl:requestURLEncodedString];
+        
+    }
+}
+
+#pragma mark 重新开始下载 第一次进去传输列表是用
+- (void)firstReDownloadAllFileFun
+{
+    if (_databaseArr && _databaseArr.count == 3) {
+    
+        NSMutableArray *downloadingArr = _databaseArr[0];
+        NSMutableArray *URLEncodedStringArr = [NSMutableArray new];
+        
+        for (couldPhoneFileModel*model in downloadingArr) {
+            if(model.curDownloadStateType == downloadStateUploading)
+            {
+                NSString *urlString = model.fileUrl;
+                NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+                [URLEncodedStringArr addObject:requestURLEncodedString];
+            }
+        }
+        
+        if(URLEncodedStringArr.count > 0){
+            [[nasDownloadManager shareManager] addDownloadWithURLs:URLEncodedStringArr];
+        }
+        
+    }
+}
+
+
+#pragma mark- download done plist Path
+- (NSString *)getDownloadDonePlistPath {
+    NSString *fileFolder = [customDownloadCacheManager getFullDirector];
+    return [fileFolder stringByAppendingPathComponent:@"nasDownloadDoneInfo.plist"];;
+}
+
+#pragma mark- download done plist
+- (NSMutableDictionary *)getDownloadDownList {
+    
+    if (!_downloadDoneList) { // 内存没有
+        _downloadDoneList = [[NSDictionary dictionaryWithContentsOfFile:[self getDownloadDonePlistPath]] mutableCopy]; // 本地加载
+        if (!_downloadDoneList) { // 本地没有,分配内存
+            _downloadDoneList = [NSMutableDictionary dictionary];
+        }
+    }
+    return _downloadDoneList;
+}
+
+/**  增加配置信息 */
+- (BOOL)saveFileInfoWithDict:(NSDictionary *)dict with:(NSString*)url {
+    
+    if(!dict || !url){
+        return NO;
+    }
+    
+    BOOL flag = NO;
+    @synchronized (self) {
+        NSString *key = url;
+        NSMutableDictionary *dictM =  [self getDownloadDownList];
+        [dictM setObject:dict forKey:key];
+        flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
+    }
+    
+    return flag;
+    
+}
+
+/**  删除配置信息 */
+- (BOOL)deleteFileInfoWithUrl:(NSString *)url {
+    if(!url){
+        return NO;
+    }
+    
+    BOOL flag = NO;
+    @synchronized (self) {
+        NSMutableDictionary *dictM =  [self getDownloadDownList];
+        [dictM removeObjectForKey:url];
+        flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
+    }
+    return flag;
+}
+
+#pragma mark-保存完成后 删除此次信息 download done plist
+- (void)deleteDownloadDonePlistInfoBy:(NSString*)fullPath
+{
+    HLog(@"deleteDownloadDonePlistInfoBy:%@",fullPath)
+    NSMutableDictionary *dictM =  [self getDownloadDownList];
+    for (NSString*key in dictM) {
+        NSDictionary*dict = dictM[key];
+        
+        if ([[dict allKeys] containsObject:@"fullPath"]) {
+            NSString * infofullPath = dict[@"fullPath"];
+
+            if([fullPath isEqualToString:infofullPath]){
+                [self deleteFileInfoWithUrl:key];
+                break;
+            }
+        }
+    }
+}
+
+#pragma mark-查询还有没有没处理的任务
+- (void)checkDownloadDonePlistInfoFun
+{
+    NSMutableDictionary *dictM =  [[self getDownloadDownList] mutableCopy];
+    if(dictM.count > 0){
+        for (NSString*key in dictM) {
+            NSDictionary*dict = dictM[key];
+            customDownloadOperation *model = [customDownloadOperation mj_objectWithKeyValues:dict];
+            
+            //判断文件是否还存在
+            if (![[NSFileManager defaultManager] fileExistsAtPath:model.fullPath]) {
+                //不存在 删除信息
+                [self deleteFileInfoWithUrl:key];
+            }
+            else{//存在 通知保存流程
+                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                    [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
+                });
+                break;
+            }
+        }
+        
+    }
+}
+@end
+

+ 47 - 0
创维盒子/双子星云手机/NAS/nasDownloadManager/nasDownloadManager.h

@@ -0,0 +1,47 @@
+//
+//  nasDownloadManager.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/8/5.
+//
+
+#import <Foundation/Foundation.h>
+#import "customDownloadOperation.h"
+NS_ASSUME_NONNULL_BEGIN
+
+/** 下载中通知 */
+#define  nasDownloadTaskExeing        @"nasDownloadTaskExeing"
+/** 下载失败通知 */
+#define  nasDownloadTaskExeError      @"nasDownloadTaskExeError"
+/** 下载完成通知 */
+#define  nasDownloadTaskExeEnd        @"nasDownloadTaskExeEnd"
+
+@interface nasDownloadManager : NSObject
+
+@property(nonatomic,strong) NSString *uid;//用户id 用来创建文件夹路径 防止不要用户的缓存关联
+@property(nonatomic,assign) NSInteger maxDownLoadCount;//默认一个
+@property(nonatomic,assign) BOOL isDownLoadIngType;//
+
+/** 实例化对象(单例) */
++ (instancetype)shareManager;
+
+#pragma mark - 队列中的任务进行操作
+
+/** 添加要下载的 网络连接  */
+- (void)addDownloadWithURLs:(NSArray *)urls;
+//在添加下载地址后 启动下载
+//- (void)beginDownload;
+
+/** 开始任务(不会自动添加任务,列队中没有就直接返回) 后续改为会自动添加任务 */
+- (void)startDownLoadWithUrl:(NSString *)url;
+
+/** 暂停任务(暂停下载url内容的任务) */
+- (void)supendDownloadWithUrl:(NSString *)url;
+
+/** 暂停当前所有的下载任务 下载任务不会从列队中删除 */
+- (void)suspendAllDownloadTask;
+
+/** 删除任务(删除下载url内容的任务) */
+- (void)deleteDownloadWithUrl:(NSString *)url;
+@end
+NS_ASSUME_NONNULL_END

+ 552 - 0
创维盒子/双子星云手机/NAS/nasDownloadManager/nasDownloadManager.m

@@ -0,0 +1,552 @@
+//
+//  nasDownloadManager.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/8/5.
+//
+
+#import "nasDownloadManager.h"
+#import "customDownloadOperation.h"
+#import "customDownloadCacheManager.h"
+
+@interface nasDownloadManager ()<NSURLSessionDataDelegate>
+//排队等候下载的下载地址数组
+@property(nonatomic,strong) NSMutableArray *downloadWaitingUrlArr;
+//正在下载的下载地址数组
+@property(nonatomic,strong) NSMutableArray *downloadingOperationArr;
+@end
+
+@implementation nasDownloadManager
++ (instancetype)shareManager {
+    static nasDownloadManager *_instance;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        _instance = [[self alloc] init];
+    });
+    return _instance;
+}
+
+- (instancetype)init {
+
+    if (self = [super init]) {
+        _maxDownLoadCount = 1;
+        //[self registeNotification];
+    }
+    return self;
+}
+
+- (NSString*)uid{
+    if(!_uid || _uid.length == 0){
+        return @"customUserName";
+    }
+    
+    return _uid;
+}
+
+/** 添加要下载的 网络连接  */
+- (void)addDownloadWithURLs:(NSArray *)urls{
+    
+    for (NSString *addUrl in urls) {
+        BOOL needAddType = YES;
+        
+        //1. 排查下载中
+        for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+            if([operationDoing.url isEqualToString:addUrl]){
+                needAddType = NO;
+                break;
+            }
+        }
+        
+        //1. 排查等待下载
+        for (NSString *waitUrl in self.downloadWaitingUrlArr) {
+            if([waitUrl isEqualToString:addUrl]){
+                needAddType = NO;
+                break;
+            }
+        }
+        
+        if(needAddType){
+            [self.downloadWaitingUrlArr addObject:addUrl];
+        }
+    }
+    
+    //启动下载
+    [self beginDownload];
+}
+
+//在添加下载地址后 启动下载
+- (void)beginDownload
+{
+    @synchronized (self) {
+        if(self.downloadingOperationArr.count == _maxDownLoadCount){
+            HLog(@"正在下载的数量达到了最大值 %ld",_maxDownLoadCount)
+            return;
+        }
+        
+        if(self.downloadWaitingUrlArr.count == 0){
+            HLog(@"没有等待中的下载任务")
+            return;
+        }
+        
+        NSInteger canAddTaskNumber = _maxDownLoadCount - self.downloadingOperationArr.count;
+        
+        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];
+            }
+            
+        }
+    
+    }
+    
+}
+
+/** 开始任务(不会自动添加任务,列队中没有就直接返回) 后续改为会自动添加任务 */
+- (void)startDownLoadWithUrl:(NSString *)url
+{
+    
+    BOOL needAddType = YES;
+    
+    //1. 排查下载中
+    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        if([operationDoing.url isEqualToString:url]){
+            needAddType = NO;
+            break;
+        }
+    }
+    
+    //1. 排查等待下载
+    for (NSString *waitUrl in self.downloadWaitingUrlArr) {
+        if([waitUrl isEqualToString:url]){
+            needAddType = NO;
+            break;
+        }
+    }
+    
+    if(needAddType){
+        [self.downloadWaitingUrlArr addObject:url];
+    }
+    
+    //启动下载
+    [self beginDownload];
+}
+
+/** 删除任务(删除下载url内容的任务) */
+- (void)deleteDownloadWithUrl:(NSString *)url
+{
+    //1.检测等待下载的任务
+    for (NSString*waitingUrl in self.downloadWaitingUrlArr) {
+        if ([waitingUrl isEqualToString:url]) {
+            [self.downloadWaitingUrlArr removeObject:waitingUrl];
+            break;
+        }
+    }
+    
+    //2.检测下载中的任务
+    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        if([operationDoing.url isEqualToString:url]){
+            [operationDoing.dataTask cancel];
+//            operationDoing.dataTask = nil;
+//            operationDoing.session = nil;
+//
+//            [operationDoing.handle closeFile];
+//            operationDoing.handle = nil;
+//
+//            [self.downloadingOperationArr removeObject:operationDoing];
+            break;
+        }
+    }
+    
+    //3. 删除本地文件
+    [customDownloadCacheManager deleteFileWithUrl:url];
+    
+    //4.进行下一个任务
+    //[self beginDownload];
+}
+
+/** 暂停任务(暂停下载url内容的任务) */
+- (void)supendDownloadWithUrl:(NSString *)url
+{
+    //1.检测等待下载的任务
+    for (NSString*waitingUrl in self.downloadWaitingUrlArr) {
+        if ([waitingUrl isEqualToString:url]) {
+            [self.downloadWaitingUrlArr removeObject:waitingUrl];
+            break;
+        }
+    }
+    
+    //2.检测下载中的任务
+    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        if([operationDoing.url isEqualToString:url]){
+            operationDoing.isManualCancel = YES;
+            
+            if(operationDoing.dataTask){
+                [operationDoing.dataTask cancel];
+            }
+//            operationDoing.dataTask = nil;
+//            operationDoing.session = nil;
+//
+//            [operationDoing.handle closeFile];
+//            operationDoing.handle = nil;
+//
+//            //删除后 didCompleteWithError 不再处理
+//            [self.downloadingOperationArr removeObject:operationDoing];
+           
+            break;
+        }
+    }
+    
+    //进行下一个任务
+    //[self beginDownload];
+}
+
+/** 暂停当前所有的下载任务 下载任务不会从列队中删除 */
+- (void)suspendAllDownloadTask
+{
+    //1.删除等待下载的任务
+    [self.downloadWaitingUrlArr removeAllObjects];
+    
+    //2.检测下载中的任务
+    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        operationDoing.isManualCancel = YES;
+        if(operationDoing.dataTask){
+            [operationDoing.dataTask cancel];
+        }
+        
+//        operationDoing.dataTask = nil;
+//        operationDoing.session = nil;
+//        [operationDoing.handle closeFile];
+//        operationDoing.handle = nil;
+    }
+
+    [self.downloadingOperationArr removeAllObjects];
+}
+
+#pragma mark 重新启动因为网络失败而停止的任务
+- (void)reDownloadNetworkTaskBy:(NSString*)url
+{
+    @synchronized (self) {
+        [self.downloadWaitingUrlArr insertObject:url atIndex:0];
+    }
+    
+    [self beginDownload];
+}
+
+#pragma mark - <NSURLSessionDataDelegate>
+
+// ssl 服务 证书信任
+- (void)URLSession:(NSURLSession *)session
+didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
+ completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{
+    if(![challenge.protectionSpace.authenticationMethod isEqualToString:@"NSURLAuthenticationMethodServerTrust"]) {
+        return;
+    }
+    
+    // 信任该插件
+    NSURLCredential *credential = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
+    // 第一个参数 告诉系统如何处置
+    completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
+}
+
+//当请求协议是https的时候回调用该方法
+//Challenge 挑战 质询(受保护空间)
+//NSURLAuthenticationMethodServerTrust 服务器信任证书
+- (void)URLSession:(NSURLSession *)session
+              task:(NSURLSessionTask *)task
+didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
+ completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * __nullable credential))completionHandler {
+    
+    if(![challenge.protectionSpace.authenticationMethod isEqualToString:@"NSURLAuthenticationMethodServerTrust"]) {
+        return;
+    }
+    
+    // 信任该插件
+    NSURLCredential *credential = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
+    // 第一个参数 告诉系统如何处置
+    completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
+    
+}
+
+
+// 接受到响应调用
+- (void)URLSession:(NSURLSession *)session
+          dataTask:(NSURLSessionDataTask *)dataTask
+didReceiveResponse:(NSURLResponse *)response
+ completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
+    
+    // 将响应交给列队处理
+    BOOL canDownload =  [self handleOperateby:dataTask WithResponse:response];
+    
+    if(canDownload){
+        // 允许下载
+        completionHandler(NSURLSessionResponseAllow);
+    }
+    else{
+        // 不允许下载
+        completionHandler(NSURLSessionResponseCancel);
+    }
+    
+}
+
+// 接受到数据碎片 的时候调用,调用多次
+- (void)URLSession:(NSURLSession *)session
+          dataTask:(NSURLSessionDataTask *)dataTask
+    didReceiveData:(NSData *)data {
+    // 接收到session 下载碎片交个列队管理
+    [self dataTask:dataTask didReceiveData:data];
+}
+
+// <NSURLSessionDataDelegate> 完成下载
+- (void)URLSession:(NSURLSession *)session
+              task:(NSURLSessionTask *)task
+didCompleteWithError:(nullable NSError *)error {
+    [self task:task didCompleteWithError:error];
+}
+
+- (void)URLSession:(NSURLSession *)session
+              task:(NSURLSessionTask *)task
+ needNewBodyStream:(void (^)(NSInputStream * _Nullable bodyStream))completionHandler {
+    
+}
+
+- (void)URLSession:(NSURLSession *)session
+              task:(NSURLSessionTask *)task
+   didSendBodyData:(int64_t)bytesSent
+    totalBytesSent:(int64_t)totalBytesSent
+totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
+    
+}
+
+#pragma mark 处理接收到的数据
+
+// 接收到相应时
+- (BOOL)handleOperateby:(NSURLSessionTask*)dataTask WithResponse:(NSURLResponse *)response {
+    
+    customDownloadOperation *operation = nil;
+    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        if(operationDoing.dataTask == dataTask){
+            operation = operationDoing;
+            break;
+        }
+    }
+    
+    if (!operation) {
+        HLog(@"没找到当前下载任务");
+        operation.downloadState = customDownloadStateFailed;
+        [dataTask cancel];
+        return NO;
+    }
+    
+    // 检查response是否是NSHTTPURLResponse的实例
+    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
+        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
+        NSInteger statusCode = httpResponse.statusCode;
+        HLog(@"HTTP Status Code: %ld", (long)statusCode);
+          
+        if(statusCode == 404){
+            operation.downloadState = customDownloadStateFailed;
+            operation.isFile404Cancel = YES;
+            return NO;
+        }
+        
+    }
+    
+    // 总的size
+    if (operation.currentSize + response.expectedContentLength == 0) {
+        HLog(@"下载数据回调异常");
+        operation.downloadState = customDownloadStateFailed;
+        return NO;
+    }
+    operation.totalSize = operation.currentSize + response.expectedContentLength;
+    
+    // 创建空的文件夹
+    if (operation.currentSize == 0) {
+        // 创建空的文件
+        [[NSFileManager defaultManager]  createFileAtPath:operation.fullPath contents:nil attributes:nil];
+    }
+    
+    // 创建文件句柄
+    operation.handle = [NSFileHandle fileHandleForWritingAtPath:operation.fullPath];
+    
+    // 文件句柄移动到文件末尾 位置 // 返回值是 unsign long long
+    [operation.handle seekToEndOfFile];
+    
+    // 开始下载记录文件下载信息
+    operation.downloadState = customDownloadStateDoing;
+    
+    return YES;
+}
+
+- (void)dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
+{
+    customDownloadOperation *operation = nil;
+    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        if(operationDoing.dataTask == dataTask){
+            operation = operationDoing;
+            break;
+        }
+    }
+    
+    if (!operation) {
+        HLog(@"没找到当前下载任务");
+        [dataTask cancel];
+        return;
+    }
+    
+    //手动取消任务
+    if (operation.isManualCancel) {
+        return;
+    }
+    
+    // 获得已经下载的文件大小
+    operation.currentSize += data.length;
+    HLog(@"currentSize:%lld---progress:%.2f", operation.currentSize, 1.00*operation.currentSize/operation.totalSize);
+
+    // 写入文件
+    if(operation.handle){
+        [operation.handle writeData:data];
+    }
+
+    // 下载中通知
+    [self operationDoningWithOperation:operation];
+}
+
+- (void)task:(NSURLSessionTask *)dataTask didCompleteWithError:(NSError *)error
+{
+    customDownloadOperation *operation = nil;
+    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        if(operationDoing.dataTask == dataTask){
+            operation = operationDoing;
+            [self.downloadingOperationArr removeObject:operationDoing];
+            break;
+        }
+    }
+    
+    if (!operation) {
+        HLog(@"没找到当前下载任务");
+        //[dataTask suspend];
+        return;
+    }
+    
+    if(operation.dataTask){
+        //[operation.dataTask cancel];
+        operation.dataTask = nil;
+        operation.session = nil;
+        
+        if(operation.handle){
+            // 关闭文件句柄
+            [operation.handle closeFile];
+            // 释放文件句柄
+            operation.handle = nil;
+        }
+    }
+    
+    if(error && error.code == -1005 && !operation.isFile404Cancel){//网络中断
+        HLog(@"reDownloadNetworkTaskBy");
+        //延时几秒再次启动这个任务
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+            [self reDownloadNetworkTaskBy:operation.url];
+        });
+        return;
+    }
+    
+    if(operation.isManualCancel){
+        [self beginDownload];
+        return;
+    }
+    
+    // 完成下载 通知 block
+    if (error ||operation.downloadState == customDownloadStateFailed) {
+        [self operationFailedWithOperation:operation];
+    } else {
+        operation.isFinished = YES;
+        operation.timeStamp = [iTools getNowTimeStamp];
+        [self operationSuccessWithOperation:operation];
+    }
+    
+    [self beginDownload];
+}
+
+
+#pragma mark 发送通知
+
+// 失败某一个operation 保存本地 通知外界
+- (void)operationFailedWithOperation:(customDownloadOperation *)operation {
+    HLog(@"DownloadTaskExeError \n %@",operation.url);
+    operation.downloadState = customDownloadStateFailed;
+    [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskExeError object:nil userInfo:@{@"operation" : operation}];
+}
+
+//外面的下载数据跳的太频繁 控制下
+static int nasDownloadTaskExeingNotNum = 0;
+
+// 重启某一个operation 保存本地 通知外界
+- (void)operationDoningWithOperation:(customDownloadOperation *)operation {
+    HLog(@"DownloadTaskExeing");
+    
+    nasDownloadTaskExeingNotNum ++;
+    if (nasDownloadTaskExeingNotNum >= 30) {
+        nasDownloadTaskExeingNotNum = 0;
+        [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskExeing object:nil userInfo:@{@"operation" : operation}];
+    }
+}
+
+// 等待某一个operation 保存本地 通知外界
+- (void)operationSuccessWithOperation:(customDownloadOperation *)operation {
+    HLog(@"DownloadTaskExeEnd \n %@",operation.url);
+    operation.downloadState = customDownloadStateCompleted;
+    [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskExeEnd object:nil userInfo:@{@"operation" : operation}];
+}
+
+-(NSURLSession*)creatNewSessionFun
+{
+    NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
+    // 设置请求超时
+    config.timeoutIntervalForRequest = -1;
+//        config.networkServiceType = NSURLNetworkServiceTypeVideo;
+    config.timeoutIntervalForResource = -1;
+//        config.TLSMaximumSupportedProtocol = kSSLProtocolAll;
+    
+    //_session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue currentQueue]];
+    NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
+    
+    return session;
+}
+
+#pragma mark - lazy load
+- (NSMutableArray *)downloadWaitingUrlArr {
+    
+    if (!_downloadWaitingUrlArr) {
+        _downloadWaitingUrlArr = [NSMutableArray array];
+    }
+    return _downloadWaitingUrlArr;
+}
+
+- (NSMutableArray *)downloadingOperationArr {
+    
+    if (!_downloadingOperationArr) {
+        _downloadingOperationArr = [NSMutableArray array];
+    }
+    return _downloadingOperationArr;
+}
+
+- (BOOL)isDownLoadIngType
+{
+    if(self.downloadingOperationArr.count >= 1){
+        return YES;
+    }
+    
+    return NO;
+}
+@end