0

Share button works in iPhone but causes a crash in iPad.

Code :

let finaltext = "Text to share"

let objectsToShare = [finaltext]

let activityController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

activityController.popoverPresentationController?.sourceView = self.view
present(activityController, animated: true, completion: nil)

Thank for Help

iOSArchitect.com
  • 4,710
  • 1
  • 14
  • 36
  • Does this answer your question? [Sharing button works perfectly on iPhone but crash on iPad](https://stackoverflow.com/questions/31506081/sharing-button-works-perfectly-on-iphone-but-crash-on-ipad) – iOSArchitect.com Jun 13 '20 at 12:33
  • Sorry but can not help me : Error in Console : > Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. – Mohamed Zied Maaloul Jun 13 '20 at 13:39
  • The error you’ve written is non-fatal. Can you reproduce again and look for the error that actually caused the thread to crash? – rpecka Jun 13 '20 at 14:47
  • Now it work but i have an other Error : [ShareSheet] connection invalidated – Mohamed Zied Maaloul Jun 13 '20 at 18:37

1 Answers1

0

Try to add sourceRect like this:

let finaltext = "Text to share"

let objectsToShare = [finaltext]

let activityController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

activityController.popoverPresentationController?.sourceView = self.view
activityController.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.maxY, width: 0, height: 0) //center bottom
present(activityController, animated: true, completion: nil)
Fabio
  • 4,374
  • 3
  • 19
  • 21