ソースを参照

1.【IOS端】音频进行下载,下载列表提示下载到文件里,查看部分文件未成功下载到文件里

huangxiaodong 11 ヶ月 前
コミット
4078be7524

+ 16 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/customDownloadManager/customDownloadOperation.m

@@ -54,4 +54,20 @@
 
 #pragma mark - setups
 
+
+#pragma mark - get download info
+// 构造回调信息
+- (NSDictionary *)downLoadInfoWithFinished:(BOOL)finished {
+    return  @{
+                    @"url" : self.url,
+               @"fileName" : self.fileName,
+               @"fullPath" : self.fullPath,
+            @"currentSize" : @(self.currentSize),
+              @"totalSize" : @(self.totalSize),
+               @"fileType" : @(self.fileType),
+              @"timeStamp" : @(self.timeStamp),
+          @"downloadState" : @(self.downloadState),
+             @"isFinished" : @(finished)
+            };
+}
 @end

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

@@ -740,6 +740,9 @@
         [boxDownloadFileManager shareInstance].isFirstAutoStartType = YES;
     }
     
+    //检测是否还有没保存的任务
+    [[boxDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
+    
     //重新下载
     [[boxDownloadFileManager shareInstance] firstReDownloadAllFileFun];
 }

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

@@ -10,9 +10,17 @@
 #import "uploadFileManager.h"
 //#import "mixDownloadManager.h"
 #import "customDownloadManager.h"
+#import "customDownloadCacheManager.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
+//【IOS端】音频进行下载,下载列表提示下载到文件里,查看部分文件未成功下载到文件里
+//问题原因:在下载音频类(即是要保存到文件app的)文件--- UIDocumentPickerViewController 弹出来后不再处理下一个 意味着快速下载完几个任务 在完成后只能保存到一个到文件 其他的因为任务完成了 不再处理保存流程
+//解决方案:创建本地持久化 每次收到下载完成通知:
+//1.先做数据保存
+//2.然后再处理文件保存流程
+//3.删除此次保存数据
+//4.UIDocumentPickerViewController 保存后访问本地持久化 查询还有没有没处理的任务
 
 #define share_box_download_tableName [[NSString alloc] initWithFormat:@"share_download_tableName_%@",[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn]
 
@@ -23,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, strong) NSMutableArray * _Nullable databaseArr;
 @property (nonatomic, assign) BOOL  isFirstAutoStartType;//启动第一次需要重新开启
 
+@property (nonatomic, strong) NSMutableDictionary * _Nullable downloadDoneList;
+
 //添加保存记录 NSArray<ShareFileDataModel>* fileListVOS;
 - (void)addBoxDownloadRecordFunBy:(NSArray*)arr complete:(custom_complete_B)complete;
 #pragma mark 读取数据库数据
@@ -43,6 +53,12 @@ NS_ASSUME_NONNULL_BEGIN
 - (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

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

@@ -341,6 +341,11 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     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){
@@ -543,4 +548,100 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     }
 }
 
+
+#pragma mark- download done plist Path
+- (NSString *)getDownloadDonePlistPath {
+    NSString *fileFolder = [customDownloadCacheManager getFullDirector];
+    return [fileFolder stringByAppendingPathComponent:@"downloadDoneInfo.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(), ^{
+                    [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
+                });
+                break;
+            }
+        }
+        
+    }
+}
 @end

+ 13 - 3
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+downloadFile.m

@@ -255,9 +255,19 @@
             if (error) {
                 // 读取出错
             } else {
-                // 上传
-                NSLog(@"fileName : %@", fileName);
-                [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
+                NSLog(@"222 fileName : %@", fileName);
+                if(!self.nasFullPath){
+                    // 下载
+                    [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
+                }
+                else{
+                    
+                    [[NSFileManager defaultManager] removeItemAtPath:self.nasFullPath error:nil];
+                    [[boxDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:self.nasFullPath];
+                    self.nasFullPath = nil;
+                    [[boxDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
+                }
+                
             }
         }];
         [urls.firstObject stopAccessingSecurityScopedResource];

+ 46 - 34
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+downloadNasFile.m

@@ -89,6 +89,8 @@
 //                 self->curYCDownloadItem = nil;
 //             }
              
+             [[boxDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:fullPath];
+             
          } else {
              HLog(@"未能将图片保存至相册");
              mainBlock(^{
@@ -116,6 +118,8 @@
 //                [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
 //                self->curYCDownloadItem = nil;
 //            }
+            
+            [[boxDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:fullPath];
         } else {
             HLog(@"未能将视频保存至相册");
             mainBlock(^{
@@ -131,6 +135,7 @@
 - (void)loadOtherDataFinishedBy:(NSString*)fullPath
 {
     NSString*filePath = fullPath;
+    self.nasFullPath = fullPath;
     
     if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
         HLog(@"没有找到文件:%@",filePath);
@@ -148,40 +153,47 @@
     [self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
 }
  
-
+//同文件 有了代理 走了 downloadFile 里面的 UIDocumentPickerDelegate
 #pragma mark - UIDocumentPickerDelegate
-- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
-    // 获取授权
-    BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
-    if (fileUrlAuthozied) {
-        // 通过文件协调工具来得到新的文件地址,以此得到文件保护功能
-        NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
-        NSError *error;
-        
-        [fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
-            // 读取文件
-            NSString *fileName = [newURL lastPathComponent];
-            NSString *pathStr = [newURL absoluteString];
-            NSError *error = nil;
-            //NSData *fileData = [NSData dataWithContentsOfURL:newURL options:NSDataReadingMappedIfSafe error:&error];
-            if (error) {
-                // 读取出错
-            } else {
-                // 上传
-                NSLog(@"fileName : %@-- %@", fileName,pathStr);
-                
-                //
-                [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
-//                if(self->curYCDownloadItem){
-//                    [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
-//                    self->curYCDownloadItem = nil;
+//- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
+//    // 获取授权
+//    BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
+//    if (fileUrlAuthozied) {
+//        // 通过文件协调工具来得到新的文件地址,以此得到文件保护功能
+//        NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
+//        NSError *error;
+//        
+//        NSURL * firstUrl = urls.firstObject;
+//        [fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
+//            // 读取文件
+//            NSString *fileName = [firstUrl lastPathComponent];
+//            NSString *pathStr = [firstUrl absoluteString];
+//            NSError *error = nil;
+//            //NSData *fileData = [NSData dataWithContentsOfURL:newURL options:NSDataReadingMappedIfSafe error:&error];
+//            if (error) {
+//                // 读取出错
+//            } else {
+//                // 上传
+//                NSLog(@"111fileName : %@ -- %@ ---%@", fileName,pathStr,self.nasFullPath);
+//                
+//                if(!pathStr || [pathStr isEqualToString:self.nasFullPath]){
+//                    pathStr = self.nasFullPath;
 //                }
-                
-            }
-        }];
-        [urls.firstObject stopAccessingSecurityScopedResource];
-    } else {
-        // 授权失败
-    }
-}
+//                
+//                //
+//                [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
+////                if(self->curYCDownloadItem){
+////                    [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
+////                    self->curYCDownloadItem = nil;
+////                }
+//                
+//                [[boxDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:pathStr];
+//                
+//            }
+//        }];
+//        [urls.firstObject stopAccessingSecurityScopedResource];
+//    } else {
+//        // 授权失败
+//    }
+//}
 @end

+ 3 - 0
创维盒子/双子星云手机/CloudPlayer/PlayerViewController.h

@@ -32,6 +32,7 @@
 #import "ComontAlretType2ViewController.h"
 //#import "mixDownloadManager.h"
 #import "customDownloadManager.h"
+#import "boxDownloadFileManager.h"
 
 @protocol PlayerViewControllerDelegate <NSObject>
 
@@ -151,6 +152,8 @@
 @property (nonatomic, copy) NSString * _Nullable downloadFileTaskUid;
 @property (nonatomic, strong) couldPhoneFileModel *curDownloadFileModel;
 
+//下载nas文件用到
+@property (nonatomic, copy) NSString*nasFullPath;
 
 /**
  * @brief 云手机类型  VIP星动云手机  SVIP星曜云手机  STAR 唔即云手机