Browse Source

1.下载初步完成

huangxiaodong 1 year ago
parent
commit
d48c28d678

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

@@ -147,4 +147,7 @@
 /* 获取云机基本通知*/
 #define getbaseInfoBeginNotification                 @"etbaseInfoBeginNot"
 
+#pragma mark 下载其它类型文件完成
+#define NotLoadOtherDataFinished  @"loadOtherDataFinished"
+
 #endif /* Notification_h */

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

@@ -162,11 +162,11 @@
                     model.downloadBoxStateType = downloadBoxStateSuspend;
                     [weakSelf handleDownloadingStateTapFunBy:YES with:model];
                 }
-                else if(model.downloadBoxStateType == downloadStateSuspend){
+                else if(model.downloadBoxStateType == downloadBoxStateSuspend){
                     model.downloadBoxStateType = downloadBoxStateDownloadloading;
                     [weakSelf handleDownloadingStateTapFunBy:NO with:model];
                 }
-                else if(model.downloadBoxStateType == downloadStateFail){
+                else if(model.downloadBoxStateType == downloadBoxStateFail){
                     [weakSelf handleUploadFailStateWith:model];
                 }
             };
@@ -524,6 +524,8 @@
     [_downloadingArr addObject:model];
     [self RefreshAllDataFun];
     
+    [[boxDownloadFileManager shareInstance] updataBoxSaveDataInFailBy:model];
+    
     NSString *urlString = model.fileUrl;
     NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     [[SGDownloadManager shareManager] startDownLoadWithUrl:requestURLEncodedString];
@@ -781,7 +783,7 @@
             
         }
         else{//保存到文件
-            
+            [self loadOtherDataFinishedBy:pathStr];
         }
     }
 }
@@ -826,55 +828,11 @@
     }];
 }
 
-////下载音频 文件等
-//- (void)loadOtherDataFinished
-//{
-//    [[downloadManager shareInstance] DownloadFileDoneOneFileFun];
-//    
-//    NSString *fileName = [self.curDownloadFileModel getFileNameFun];
-//    NSString*filePath = [cachesFileManager getFilePathWithName:fileName type:DownLoadFileType];
-//    
-//    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
-//        HLog(@"没有找到文件:%@",fileName);
-//        return;
-//    }
-//    
-//    NSURL * fileURL = [NSURL fileURLWithPath:filePath];
-//    UIDocumentPickerViewController *documentPickerVC = [[UIDocumentPickerViewController alloc] initWithURL:fileURL inMode:UIDocumentPickerModeExportToService];
-//    // 设置代理
-//    documentPickerVC.delegate = self;
-//    // 设置模态弹出方式
-//    documentPickerVC.modalPresentationStyle = UIModalPresentationFormSheet;
-//    [self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
-//}
-// 
-//
-//#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];
-//            NSError *error = nil;
-//            //NSData *fileData = [NSData dataWithContentsOfURL:newURL options:NSDataReadingMappedIfSafe error:&error];
-//            if (error) {
-//                // 读取出错
-//            } else {
-//                // 上传
-//                NSLog(@"fileName : %@", fileName);
-//                [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
-//            }
-//        }];
-//        [urls.firstObject stopAccessingSecurityScopedResource];
-//    } else {
-//        // 授权失败
-//    }
-//}
+//下载音频 文件等
+- (void)loadOtherDataFinishedBy:(NSString*)fullPath
+{
+    [[NSNotificationCenter defaultCenter] postNotificationName:NotLoadOtherDataFinished object:fullPath userInfo:nil];
+}
+
 @end
 

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

@@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)deleteBoxSaveFileRecordBy:(NSMutableArray *)delArr;
 
 #pragma mark 更新本地数据库记录
-//- (void)updataBoxSaveDataBy:(downStatusModel*)downStatusMod;
+- (void)updataBoxSaveDataInFailBy:(ShareFileDataModel*)dataModel;
 
 #pragma mark 开始下载文件 ShareFileDataModel
 - (void)beginDownloadFilesByUrls:(NSArray *)urlArr;

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

@@ -160,62 +160,37 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             }
         }];
         
+        
+        //3.取消下载
+        NSString *urlString = dataModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        [[SGDownloadManager shareManager] cancelDownloadWithUrl:requestURLEncodedString];
     }
     
 }
 
 
 #pragma mark 更新本地数据库记录
-//- (void)updataBoxSaveDataBy:(downStatusModel*)downStatusMod
-//{
-//    
-//    //1.修改数据库
-//    NSMutableArray *firstArr = [NSMutableArray arrayWithArray:_databaseArr[0]] ;
-//    NSMutableArray *needUpdatArr = [NSMutableArray new];
-//    
-//    for (downStatusDataModel*updataModel in downStatusMod.data) {
-//
-//        for (ShareFileDataModel* model in firstArr) {
-//            if ([updataModel.url isEqualToString:model.fileUrl]) {
-//                if (updataModel.curStatus == 0
-//                    || updataModel.curStatus == 3) {
-//                    //不用处理
-//                }
-//                else if (updataModel.curStatus == 1) {
-//                    
-//                    [self handleDatabaseArrByDelete:model];
-//                    
-//                    //成功
-//                    model.saveboxStateType = saveBoxStateDone;
-//                    [needUpdatArr addObject:model];
-//                    
-//                    NSMutableArray *doneArr = _databaseArr[1];
-//                    [doneArr addObject:model];
-//                    
-//                }
-//                else{
-//                    [self handleDatabaseArrByDelete:model];
-//                    
-//                    //失败
-//                    model.saveboxStateType = saveBoxStateFail;
-//                    [needUpdatArr addObject:model];
-//                    
-//                    NSMutableArray *failArr = _databaseArr[2];
-//                    [failArr addObject:model];
-//                }
-//                break;
-//            }
-//        }
-//    }
-//    
-//    if(needUpdatArr.count > 0){
-//        [ShareFileDataModel bg_saveOrUpdateArrayAsync:needUpdatArr complete:^(BOOL isSuccess) {
-//
-//        }];
-//    }
-//    
-//    
-//}
+- (void)updataBoxSaveDataInFailBy:(ShareFileDataModel*)dataModel
+{
+    
+    //1.修改数据库
+    if(_databaseArr.count == 3){
+        NSMutableArray *failArr = _databaseArr[2];
+        NSMutableArray *ingArr = _databaseArr[0];
+        for (ShareFileDataModel* model in failArr) {
+            if (dataModel.bg_id.integerValue == model.bg_id.integerValue) {
+                [failArr removeObject:model];
+                [ingArr addObject:dataModel];
+                
+            }
+        }
+    }
+   
+    [dataModel bg_saveOrUpdateAsync:^(BOOL isSuccess) {
+            
+    }];
+}
 
 #pragma mark 开始下载文件
 - (void)beginDownloadFilesByUrls:(NSArray *)urlArr{
@@ -258,7 +233,6 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 {
     SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
     [self handldDownloadDoneDataBy:model];
-    [[SGDownloadManager shareManager] cancelDownloadWithUrl:model.url];
     HLog(@"下载成功");
 }
 

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

@@ -23,7 +23,7 @@
 #import "MySetViewController.h"
 #import "receiveView.h"
 
-@interface uploadFileRecordViewController ()<UIScrollViewDelegate>
+@interface uploadFileRecordViewController ()<UIScrollViewDelegate,UIDocumentPickerDelegate>
 
 //选中的项
 @property (nonatomic, strong) NSMutableArray *indexPathsForSelectedItems;
@@ -71,6 +71,9 @@
     [[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(loadOtherDataFinishedFun:)  name:NotLoadOtherDataFinished  object:nil];
+    
+    
     [self.view setBackgroundColor:[UIColor whiteColor]];
     
     self.titleLabel.text = NSLocalizedString(@"my_set_no_File_Transfer_List",nil) ;
@@ -1114,4 +1117,66 @@
     _curReceiveView.isReceiveType = isReceiveType;
     [_curReceiveView getAllDataFun];
 }
+
+- (void)loadOtherDataFinishedFun:(NSNotification*)not
+{
+    NSString *fullPath = [not object];
+    if(fullPath
+       && [fullPath isKindOfClass:[NSString class]]
+       && fullPath.length >0){
+        [self loadOtherDataFinishedBy:fullPath];
+    }
+}
+
+//下载音频 文件等
+- (void)loadOtherDataFinishedBy:(NSString*)fullPath
+{
+    
+    NSString*filePath = fullPath;
+    
+    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
+        HLog(@"没有找到文件:%@",filePath);
+        return;
+    }
+    
+    NSURL * fileURL = [NSURL fileURLWithPath:filePath];
+    
+    UIDocumentPickerViewController *documentPickerVC = [[UIDocumentPickerViewController alloc] initWithURL:fileURL inMode:UIDocumentPickerModeExportToService];
+    // 设置代理
+    documentPickerVC.delegate = self;
+    // 设置模态弹出方式
+    documentPickerVC.modalPresentationStyle = UIModalPresentationFormSheet;
+    [self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
+}
+ 
+
+#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];;
+            }
+        }];
+        [urls.firstObject stopAccessingSecurityScopedResource];
+    } else {
+        // 授权失败
+    }
+}
 @end