Sharing Video PHAsset via UIActivityController

我只是一个虾纸丫 提交于 2019-12-09 16:55:38

问题


I am trying to share video PHAsset via UIActivityController using requestAVAsset. This works with Messaging, but not with AirDrop, indicating as 'Failed'.

PHCachingImageManager.default().requestAVAsset(forVideo: asset, options: nil, resultHandler:
    { (givenAsset, audioMix, info) in

        let videoAsset = givenAsset as! AVURLAsset
        let videoURL = videoAsset.url

        DispatchQueue.main.async {
            let activityViewController = UIActivityViewController(
                activityItems: [videoURL],
                applicationActivities: nil)
            activityViewController.excludedActivityTypes = [UIActivityType.saveToCameraRoll]

            if let popoverPresentationController = activityViewController.popoverPresentationController {
                popoverPresentationController.barButtonItem = (sender)
            }

            self.present(activityViewController, animated: true, completion: nil)
        }
})

This seems to properly put up UIActivityController and only work with certain activities:

  • Messaging - ✔️Works, properly exports video.
  • AirDrop - ✖️Shows "Failed"
  • Dropbox - ✖️Puts up the proper Dropbox View, yet says "Unknown error occurred"


回答1:


I've run into similarly odd behavior when working with PHAssets. My guess is this is a (purposely) undocumented security/sandboxing restriction.

I was able to work around this problem by copying the underlying file to a user directory, and then performing the operation on the copied file.

I did this in a loop. Occasionally, the copy fails with a vague file permissions error. When it does, I retry it after a few seconds (using DispatchQueue.main.asyncAfter). Eventually, it works!



来源:https://stackoverflow.com/questions/43707939/sharing-video-phasset-via-uiactivitycontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!