【问题标题】:Export LivePhoto via UIActivityViewController - Swift通过 UIActivityViewController 导出 LivePhoto - Swift
【发布时间】:2019-03-20 13:22:03
【问题描述】:

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

    }

提前感谢您!

【问题讨论】:

    标签: swift uiactivityviewcontroller phlivephoto


    【解决方案1】:

    我能够使用这段代码正确导出图像:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-07
      • 2014-10-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多