I have a class with UIView and want to share a URL link, what is the proper way of adding the share sheet in UIView?
My current code is attempting to call the share sheet via a button click:
//share app
@IBAction func shareAppBtn(sender: AnyObject ) {
print("shareAppBtn tapped")
let myWebsite = NSURL(string:"http://www.google.com/")
guard let url = myWebsite else {
print("nothing found")
return
}
let shareItems:Array = [url]
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
self.window?.rootViewController!.presentViewController(activityViewController, animated: true, completion: nil)
}
I tried to use the root view of the current UIView but I receive an error:
Warning: Attempt to present <UIActivityViewController: on <RAMAnimatedTabBarController.RAMAnimatedTabBarController: which is already presenting <SideMenu.UISideMenuNavigationController: Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController:)
Thanks.