Video sharing via UIActivityController

I am trying to transfer a PHAsset video through a UIActivityController using requestAVAsset. This works with Messaging, but not with AirDrop indicating "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 be correctly placed by the UIActivityController and only works with certain actions:

  • Messages - βœ”οΈWorks, correctly exports the video.
  • AirDrop - "Shows" Failure "
  • Dropbox - βœ–οΈ Substitutes the correct view of Dropbox but says "Unknown error"

enter image description here

+7
ios swift video uiactivityviewcontroller phasset
source share
1 answer

I encountered the same odd behavior when working with PHAssets. I assume this is an (intentionally) undocumented security / sandbox restriction.

I was able to work around this problem by copying the main file to the user's directory, and then performing the operation in the copied file.

I did it in a loop. Sometimes a copy fails with an unspecified file resolution error. When this happens, I will try to repeat it in a few seconds (using DispatchQueue.main.asyncAfter ). In the end, it works!

+4
source share

All Articles