Sharing Video PHAsset via UIActivityController

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"

  • 在这里输入图像描述


    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!

    链接地址: http://www.djcxy.com/p/96230.html

    上一篇: 键盘在UICollectionViewController中断布局

    下一篇: 通过UIActivityController共享视​​频PHAsset