0

I have a piece of code that works very well on iPhone, but not on the iPad. It is like the window is there but not visible...

enter image description here

func userDidTapShare()
{
    print("Share")
    let mediaURL = URL(fileURLWithPath: Constants.Path.mainFolder.stringByAppendingPathComponent(path:mediaPath))
    let activityItems: [Any] = [mediaURL, "Check this out!"]

    let activityVC = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.view
    activityVC.popoverPresentationController?.sourceRect = view.frame

    self.present(activityVC, animated: true, completion: nil)
}

The window doesn't present on the iPad.

Any idea?

ΩlostA
  • 2,501
  • 5
  • 27
  • 63

1 Answers1

1

Your sourceRect is an issue. Since it takes the entire screen (because you used the view frame), the popover is actually presented outside the frame of the screen.

For example, if you want it to show out of top left corner:

activityVC.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: 1, height: 1)
Adis
  • 4,512
  • 2
  • 33
  • 40