通过 UIActivityViewController 导出 LivePhoto - Swift

Posted

技术标签:

【中文标题】通过 UIActivityViewController 导出 LivePhoto - Swift【英文标题】:Export LivePhoto via UIActivityViewController - 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)
        )

    

提前感谢您!

【问题讨论】:

【参考方案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)
            )

【讨论】:

以上是关于通过 UIActivityViewController 导出 LivePhoto - Swift的主要内容,如果未能解决你的问题,请参考以下文章

绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合

如何通过 Windows Azure 通过 GCM 通过唯一 ID 发送特定 Android 设备的通知?

下拉框多选框单选框 通过TagHelper绑定数据

酶:测试孩子通过安装渲染失败,但通过浅时通过

java是通过值传递,也就是通过拷贝传递——通过方法操作不同类型的变量加深理解

通过代码进行 Spring 配置与通过注释进行配置