0

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

    }

先感谢您!

4

1 回答 1

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)
            })
于 2019-03-20T16:39:37.073 回答