Skip to content

Instantly share code, notes, and snippets.

@nguni52
Last active August 15, 2017 12:23
Show Gist options
  • Save nguni52/cc77e5630555aa884cdf0e8045d516bb to your computer and use it in GitHub Desktop.
Save nguni52/cc77e5630555aa884cdf0e8045d516bb to your computer and use it in GitHub Desktop.
This shows how to implement a share via social media and text or any other app that allows sharing on iOS
@IBAction func shareButtonTapped(_ sender: Any) {
debugPrint("share button has been tapped")
// text to share
let text = self.currSelectedStore + " have a special! Take a look."
// let urlToShare : storeSpecialsImageUrl
// If you want to put an image
let image : UIImage = self.specialsImageView.image!
// set up activity view controller
let activityViewController = UIActivityViewController(activityItems: [text, storeSpecialsImageUrl, image], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment