有没有办法将实时照片保存到照片库?

kee*_*n3d 8 cocoa-touch ios ios9.1 phlivephoto

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

jlw*_*jlw 15

    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);
        }];
Run Code Online (Sandbox Code Playgroud)

  • 此解决方案工作正常,但在将元数据添加到我的 .mov 和 .jpg 文件之前,我收到了 Cocoa 错误 -1(无法完成操作。)错误。在 iOS 11 设备上复制它。 (2认同)

car*_*196 5

斯威夫特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")
    }
Run Code Online (Sandbox Code Playgroud)