ios - UIActivityViewController in Swift Crashes on iPad -


i making share function in game , have code , works fine on iphone when test on ipad, when tap share button app crashes. using following code share button

let texttoshare = "check out website!"  if let mywebsite = nsurl(string: "http://www.apple.com/") {    let objectstoshare = [texttoshare, mywebsite]    let activityvc = uiactivityviewcontroller(activityitems: objectstoshare, applicationactivities: nil)    self.view?.window?.rootviewcontroller?.presentviewcontroller(activityvc, animated: true, completion: nil) } 

the uiactivityviewcontroller's has non-null popoverpresentationcontroller property when running on ipad. so, try below.

if let wppc = activityvc.popoverpresentationcontroller {     wppc.sourceview = view     //  or     wppc.barbuttonitem = bar button item } presentviewcontroller( activityvc, animated: true, completion: nil ) 

Popular posts from this blog