首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法把一张照片保存到照片库?

有没有办法把一张照片保存到照片库?
EN

Stack Overflow用户
提问于 2015-10-01 18:00:49
回答 2查看 5.7K关注 0票数 10

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-02 16:44:53

代码语言:javascript
复制
    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);
        }];
票数 17
EN

Stack Overflow用户

发布于 2017-02-03 22:10:56

Swift 3:

代码语言:javascript
复制
PHPhotoLibrary.shared().performChanges({ 

        let request = PHAssetCreationRequest.forAsset()

        request.addResource(with: .photo, fileURL: photoURL, options: nil)
        request.addResource(with: .pairedVideo, fileURL: videoURL, options: nil)

    }) { (success, error) in

        print(success)
        print(error?.localizedDescription ?? "error")
    }
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32893993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档