我能够成功创建一个具有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)
        })

    }


先感谢您!

最佳答案

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

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)
            })

关于swift - 通过UIActivityViewController导出LivePhoto-Swift,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55261749/

10-10 20:34