At https://developer.apple.com/reference/uikit/uiactivityviewcontroller it says about UIActivityViewController,
"When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally."
So I wrote the following code to set an instance of the UIActivityViewController to be a popover:
activityViewController.modalPresentationStyle = UIModalPresentationStyle.popover
What do I set the modalPresentationStyple property to if I present the instance of the UIActivityViewController to present modally?
I figured it out. I had to set other properties. Here's my code:
@IBAction func showMore(_ sender: UIBarButtonItem) {
let string = "Hello World!"
let activityItems = [string]
let activityViewController = UIActivityViewController.init(activityItems: activityItems, applicationActivities: nil)
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad) {
activityViewController.modalPresentationStyle = UIModalPresentationStyle.popover
activityViewController.preferredContentSize = CGSize(width: 0, height: 0)
activityViewController.popoverPresentationController?.barButtonItem = barButtonItemMore
present(activityViewController, animated: true, completion: nil)
}
else
{
present(activityViewController, animated: true, completion: nil)
}
}