Browse Source

1.下载过程中 再去下载 闪退修复

huangxiaodong 1 year ago
parent
commit
ae04607f57

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

@@ -98,12 +98,13 @@
                 
                 NSURLSession *session = [self creatNewSessionFun];
                 customDownloadOperation * operation = [[customDownloadOperation alloc] initWith:downloadUrl session:session];
-                [operation.dataTask resume];
                 
                 //等待下载中的任务
                 [self.downloadWaitingUrlArr removeObjectAtIndex:0];
                 //添加到下载中数组
                 [self.downloadingOperationArr addObject:operation];
+                
+                [operation.dataTask resume];
             }
             
         }

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

@@ -94,7 +94,8 @@
 {
     [super viewWillAppear:animated];
     
-    if(![iTools checkFreeDiskSpaceInBytesIsOK:500*1024*1024]){
+    if(![iTools checkFreeDiskSpaceInBytesIsOK:500*1024*1024]
+       && _isDownloadingType){
         mainBlock(^{
             [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
         });

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

@@ -15,9 +15,12 @@
 
 - (NSString*)fileUrl
 {
-    NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
-    NSString *curFileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,self.path];
-    return curFileUrl;
+    if(!_fileUrl || _fileUrl.length ==0)
+    {
+        NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
+        _fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,self.path];
+    }
+    return _fileUrl;
 }
 
 #pragma mark - get download info

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

@@ -74,10 +74,13 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
 
 //添加保存记录
 - (void)addNasDownloadRecordFunBy:(NSArray*)arr complete:(custom_complete_Arr)complete{
+    KWeakSelf
     if(arr && arr.count >0 ){
         //1.排重处理
         [self getDataInDatabaseFun:NO complete:^(NSMutableArray * _Nonnull Arr) {
-            [self filterDownloadingTaskFunWithNewTaskArr:arr complete:complete];
+            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
+                [weakSelf filterDownloadingTaskFunWithNewTaskArr:arr complete:complete];
+            });
         }];
     }
 }
@@ -88,7 +91,8 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
     
     NSMutableArray * downloadingArr = [NSMutableArray new];
     if(_databaseArr && _databaseArr.count == 3){
-        downloadingArr = _databaseArr[0];
+        //downloadingArr = _databaseArr[0];
+        downloadingArr = [NSMutableArray arrayWithArray:_databaseArr[0]];
     }
     
     
@@ -109,6 +113,9 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
             [addTaskArr addObject:model];
         }
     }
+    HLog(@"遍历下载数组 看是否有任务重复结束")
+    
+    downloadingArr = nil;
     
     if(addTaskArr.count >0){
         KWeakSelf
@@ -335,7 +342,7 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
         [self handldDownloadFailDataBy:model];
     }
     
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+    mainBlock(^{
         [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
         
         [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];

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

@@ -46,11 +46,15 @@
 /** 添加要下载的 网络连接  */
 - (void)addDownloadWithURLs:(NSArray *)urls{
     
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    
+    NSMutableArray *curWaitingUrlArr = [NSMutableArray arrayWithArray:self.downloadWaitingUrlArr];
+    
     for (NSString *addUrl in urls) {
         BOOL needAddType = YES;
         
         //1. 排查下载中
-        for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
             if([operationDoing.url isEqualToString:addUrl]){
                 needAddType = NO;
                 break;
@@ -58,7 +62,7 @@
         }
         
         //1. 排查等待下载
-        for (NSString *waitUrl in self.downloadWaitingUrlArr) {
+        for (NSString *waitUrl in curWaitingUrlArr) {
             if([waitUrl isEqualToString:addUrl]){
                 needAddType = NO;
                 break;
@@ -131,8 +135,13 @@
     
     BOOL needAddType = YES;
     
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    
+    NSMutableArray *curWaitingUrlArr = [NSMutableArray arrayWithArray:self.downloadWaitingUrlArr];
+    
+    
     //1. 排查下载中
-    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+    for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
         if([operationDoing.url isEqualToString:url]){
             needAddType = NO;
             break;
@@ -140,7 +149,7 @@
     }
     
     //1. 排查等待下载
-    for (NSString *waitUrl in self.downloadWaitingUrlArr) {
+    for (NSString *waitUrl in curWaitingUrlArr) {
         if([waitUrl isEqualToString:url]){
             needAddType = NO;
             break;
@@ -158,9 +167,14 @@
 /** 删除任务(删除下载url内容的任务) */
 - (void)deleteDownloadWithUrl:(NSString *)url
 {
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    
+    NSMutableArray *curWaitingUrlArr = [NSMutableArray arrayWithArray:self.downloadWaitingUrlArr];
+    
+    
     //1.检测等待下载的任务
     BOOL isWaitingUrlType = NO;
-    for (NSString*waitingUrl in self.downloadWaitingUrlArr) {
+    for (NSString*waitingUrl in curWaitingUrlArr) {
         if ([waitingUrl isEqualToString:url]) {
             [self.downloadWaitingUrlArr removeObject:waitingUrl];
             isWaitingUrlType = YES;
@@ -170,7 +184,7 @@
     
     //2.检测下载中的任务
     if(!isWaitingUrlType){
-        for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+        for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
             if([operationDoing.url isEqualToString:url]){
                 operationDoing.isManualCancel = YES;
                 if(operationDoing.dataTask){
@@ -198,8 +212,13 @@
 /** 暂停任务(暂停下载url内容的任务) */
 - (void)supendDownloadWithUrl:(NSString *)url
 {
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    
+    NSMutableArray *curWaitingUrlArr = [NSMutableArray arrayWithArray:self.downloadWaitingUrlArr];
+    
+    
     //1.检测等待下载的任务
-    for (NSString*waitingUrl in self.downloadWaitingUrlArr) {
+    for (NSString*waitingUrl in curWaitingUrlArr) {
         if ([waitingUrl isEqualToString:url]) {
             [self.downloadWaitingUrlArr removeObject:waitingUrl];
             break;
@@ -207,7 +226,7 @@
     }
     
     //2.检测下载中的任务
-    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+    for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
         if([operationDoing.url isEqualToString:url]){
             operationDoing.isManualCancel = YES;
             
@@ -234,11 +253,13 @@
 /** 暂停当前所有的下载任务 下载任务不会从列队中删除 */
 - (void)suspendAllDownloadTask
 {
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    
     //1.删除等待下载的任务
     [self.downloadWaitingUrlArr removeAllObjects];
     
     //2.检测下载中的任务
-    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+    for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
         operationDoing.isManualCancel = YES;
         if(operationDoing.dataTask){
             [operationDoing.dataTask cancel];
@@ -354,7 +375,8 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
 - (BOOL)handleOperateby:(NSURLSessionTask*)dataTask WithResponse:(NSURLResponse *)response {
     
     customDownloadOperation *operation = nil;
-    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
         if(operationDoing.dataTask == dataTask){
             operation = operationDoing;
             break;
@@ -423,7 +445,8 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
 - (void)dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
 {
     customDownloadOperation *operation = nil;
-    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
         if(operationDoing.dataTask == dataTask){
             operation = operationDoing;
             break;
@@ -457,7 +480,8 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
 - (void)task:(NSURLSessionTask *)dataTask didCompleteWithError:(NSError *)error
 {
     customDownloadOperation *operation = nil;
-    for (customDownloadOperation *operationDoing in self.downloadingOperationArr) {
+    NSMutableArray *curDownloadingOperationArr = [NSMutableArray arrayWithArray:self.downloadingOperationArr];
+    for (customDownloadOperation *operationDoing in curDownloadingOperationArr) {
         if(operationDoing.dataTask == dataTask){
             operation = operationDoing;
             [self.downloadingOperationArr removeObject:operationDoing];