简体   繁体   中英

Share button work in Iphone and not work in iPad - IOS SWIFT

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM