我试图弄清楚如何以编程方式显示系统共享菜单,但我能找到的所有信息都是how to register an app to said menu。
如何以编程方式调用对话框?
答案 0 :(得分:4)
你需要创建一个UIActivityViewController的实例,这是一个简单的例子
let objectsToShare = ["a string"]
let activityController = UIActivityViewController(
activityItems: objectsToShare,
applicationActivities: nil)
// if your app can run on an iPad, this menu
// will present as a pop over controller
// and as such, needs to be configured
// consider the bar button item property
// if needed
// should be the rect that the pop over should anchor to
activityController.popoverPresentationController?.sourceRect = view.frame
activityController.popoverPresentationController?.sourceView = view
activityController.popoverPresentationController?.permittedArrowDirections = .any
// present the controller
present(activityController, animated: true, completion: nil)