Search code examples
iosswiftuiactivityviewcontroller

Get UIActivityViewController (share) to show on iPad in the way it shows on iPhone?


I have a share button. When the share button is tapped, the view controller runs code like this:

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}

@IBOutlet weak var popOverView: UIView!
@IBOutlet weak var shareButton: UIButton!
@IBAction func share()
{
    let text = "Sharing."
    if let url = URL(string: "https://www.apple.com")
    {
        let items = [text,url] as [Any]
        let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
        if let popoverViewController = activityViewController.popoverPresentationController
        {
            popoverViewController.sourceView = popOverView
            // popoverViewController.sourceRect = popOverView.frame
        }
        present(activityViewController, animated: true, completion: nil)
        print(activityViewController.popoverPresentationController?.sourceView)
    }
}

}

This works, but produces this:

Weird iPad image

when I want something like this, because the content to be shared won't be on this view controller:

iPhone UIActivityView

How do I get the screen that I want?


Solution

  • Unfortunately that is not possible on iPad.

    Sorry for the bad news!


    If you truly, truly wanted that look, you'd have to make a completely custom view controller that sits down there (ie, no connection to UIActivityViewController), of course that would be an unrealistic amount of work.