Pārlūkot izejas kodu

1.文件下载后到存储到文件

huangxiaodong 1 gadu atpakaļ
vecāks
revīzija
658b00c8b4

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

@@ -13,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 @interface PlayerViewController (downloadFile)
 - (void)begindownloadFileFun:(NSNotification *)notification;
 - (void)downloadFileFunServiceResponseFun:(NSData *)fileData with:(BOOL)isDownloadDone;
+- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls;
 @end
 
 NS_ASSUME_NONNULL_END

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

@@ -145,7 +145,10 @@
     else if([self.curDownloadFileModel.fileType isEqualToString:@"video"]){
         [self loadVideoFinished];
     }
-    
+    else
+    {
+        [self loadOtherDataFinished];
+    }
 }
 
 
@@ -197,4 +200,57 @@
         [[downloadManager shareInstance] DownloadFileDoneOneFileFun];
     }];
 }
+
+//下载音频 文件等
+- (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 {
+        // 授权失败
+    }
+}
+
+
 @end

+ 6 - 2
创维盒子/双子星云手机/CloudPlayer/PlayerViewController.mm

@@ -77,7 +77,8 @@ RecoderManagerDelegate,
 AudioRecoderMamagerDelegate,
 RCLiveSteamManagerDelegate,
 UITextFieldDelegate,
-ComontAlretViewControllerDelegate>
+ComontAlretViewControllerDelegate,
+UIDocumentPickerDelegate>
 {
 //    __block int _ihandle;
     
@@ -3411,5 +3412,8 @@ static int  couneeee = 0;
     return YES;
 }
 
-
+- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls
+{
+    [self documentPicker:controller didPickDocumentsAtURLs:urls];
+}
 @end