本文介绍了通过UIActivityController共享视​​频PHAsset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用requestAVAsset通过 UIActivityController 分享视频 PHAsset 。这适用于Messaging,但不适用于AirDrop,表示为'失败'。

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

这似乎正确地提出了 UIActivityController 并且仅适用于某些活动:

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


  • 消息传递 - ✔️Works,正确导出视频。

  • AirDrop - ✖️Shows失败

  • Dropbox - ✖️提供正确的Dropbox视图,但说发生了未知错误

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

推荐答案

使用PHAssets时,我遇到了类似的奇怪行为。我猜这是一个(故意)未记录的安全/沙盒限制。

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.

我是在一个循环中完成的。有时,复制失败并出现模糊的文件权限错误。如果是这样,我会在几秒后重试它(使用 DispatchQueue.main.asyncAfter )。最终,它有效!

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!

这篇关于通过UIActivityController共享视​​频PHAsset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 12:05