Is there a way to save a Live Photo to the Photo L

2019-02-02 01:19发布

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?

2条回答
孤傲高冷的网名
2楼-- · 2019-02-02 01:34

Swift 3:

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")
    }
查看更多
Animai°情兽
3楼-- · 2019-02-02 01:45
    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);
        }];
查看更多
登录 后发表回答