将资产复制到文档目录

时间:2016-02-15 08:56:56

标签: ios

我正在使用ctAssetPickerController来挑选视频和图片。用户完成选择视频和图像后,我想将它们复制到另一个文件夹。我正在使用导出会话和requestAvAssetForVideo方法,但问题是它一次只复制一个文件,我无法获取用户正在选择的文件的名称,而且它只是复制视频。我如何复制图像?以下是我的代码。

- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{

        PHImageManager *manager = [PHImageManager defaultManager];

    [manager requestAVAssetForVideo:obj options:PHVideoRequestOptionsDeliveryModeAutomatic resultHandler:^(AVAsset * asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
        AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];        
        NSString *imageName = @"img_o462.mp4";
        NSString *selectedFilesCopyPath = [[self getRootFolderPath] stringByAppendingString:@"/Photos"];

        if (![[NSFileManager defaultManager]fileExistsAtPath:selectedFilesCopyPath]) {
            [[NSFileManager defaultManager]createDirectoryAtPath:selectedFilesCopyPath withIntermediateDirectories:NO attributes:nil error:nil];
        }

        NSString *copyPath = [selectedFilesCopyPath stringByAppendingString:[NSString stringWithFormat:@"/%@",imageName]];
        //            NSError *copyError= nil;

        exporter.outputURL = [NSURL fileURLWithPath:copyPath];
        exporter.outputFileType = AVFileTypeMPEG4;

        [exporter exportAsynchronouslyWithCompletionHandler:^{
            // here your file will be saved into file system at specified exportUrl
            NSLog(@"file copied");

            if (exporter.status == AVAssetExportSessionStatusCompleted) {
                NSLog(@"success");
                [self showErrorAlert:@"Success"];
            } else {
                NSLog(@"error: %@", [exporter error]);
                [self showErrorAlert:exporter.error];
            }
        }];

    }];
}

0 个答案:

没有答案