有一种方法来保存活动照片到照片库? [英] Is there a way to save a Live Photo to the Photo Library?

查看:1059
本文介绍了有一种方法来保存活动照片到照片库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将存储的图片和视频文件传递给:
PHLivePhoto.requestLivePhotoWithResourceFileURLs ,并获得 PHLivePhoto 对象,我可以在 PHLivePhotoView 中显示。但我想知道,一旦我有一个 PHLivePhoto 是有办法保存到照片库吗?

I'm passing stored image and video files to: PHLivePhoto.requestLivePhotoWithResourceFileURLs and getting a PHLivePhoto object that I can display in PHLivePhotoView. But I am wondering, once I have a PHLivePhoto is there a way to save it to the Photo Library?

推荐答案

    NSURL *photoURL = ...;
    NSURL *videoURL = ...;   

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
            PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];


            //These types should be inferred from your files

            //PHAssetResourceCreationOptions *photoOptions = [[PHAssetResourceCreationOptions alloc] init];
            //photoOptions.uniformTypeIdentifier = @"public.jpeg";

            //PHAssetResourceCreationOptions *videoOptions = [[PHAssetResourceCreationOptions alloc] init];
            //videoOptions.uniformTypeIdentifier = @"com.apple.quicktime-movie";

            [request addResourceWithType:PHAssetResourceTypePhoto fileURL:photoURL options:nil /*photoOptions*/];
            [request addResourceWithType:PHAssetResourceTypePairedVideo fileURL:videoURL options:nil /*videoOptions*/];

        } completionHandler:^(BOOL success, NSError * _Nullable error) {
            NSLog(@"success? %d, error: %@",success,error);
        }];

这篇关于有一种方法来保存活动照片到照片库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆