我正在开发一个应用程序,希望使用uiactivityviewcontroller共享保存在我的文档目录中的图像、视频和其他文件。 图像和文件共享正常工作。 图像共享的代码:
var textToShare : Any!
textToShare = UIImage(data:data)//data of an image
代码针对存储在文档目录中的其他文件。
var textToShare : Any!
textToShare = url//url of file saved into document directory
但是我不知道如何分享视频。在此之后,我使用以下代码来使用activityviewcontroller。
let activityViewController = UIActivityViewController(activityItems: [textToShare], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)