通过UIActivityViewController-Swift

时间:2019-03-20 13:22:04

标签: swift uiactivityviewcontroller phlivephoto

我能够成功创建一个具有jpeg和mov文件的LivePhoto,并将其显示在屏幕上。

现在,我无法将LivePhoto保存到库中。使用以下代码,我收到错误:“资源不可用”。

 @IBAction func exportButton(_ sender: Any) {

        PHLivePhoto.request(withResourceFileURLs: [imgUrl!,videoUrl!], placeholderImage: previewImg, targetSize: CGSize.zero, contentMode: PHImageContentMode.aspectFit, resultHandler: { (livePhoto,info) -> Void in

            let items = [livePhoto] as [Any]
            let ac = UIActivityViewController(activityItems: items as [Any], applicationActivities: nil)
            self.present(ac, animated: true)
        })

    }

先谢谢您!

1 个答案:

答案 0 :(得分:0)

我可以使用以下代码正确导出图像:

PHPhotoLibrary.shared().performChanges({
                let creationRequest = PHAssetCreationRequest.forAsset()
                let options = PHAssetResourceCreationOptions()
                creationRequest.addResource(with: PHAssetResourceType.pairedVideo, fileURL: videoUrl!, options: options)
                creationRequest.addResource(with: PHAssetResourceType.photo, fileURL: imgUrl!, options: options)
            }, completionHandler: { (success, error) in
                if error != nil {
                    print(error)
                }
                print(success)
            })