I need to show an option to share some details like on Android using Swift. How do I show the screen with a list of applications to share? Please see the below screenshot:
Asked
Active
Viewed 287 times
-3
-
1[Add sharing to your Swift app via UIActivityViewController](https://www.codingexplorer.com/sharing-swift-app-uiactivityviewcontroller/), [How to share content with UIActivityViewController](https://www.hackingwithswift.com/example-code/uikit/how-to-share-content-with-uiactivityviewcontroller), [UIActivityViewController by example](https://www.hackingwithswift.com/articles/118/uiactivityviewcontroller-by-example), [How To Share Content With UIActivityViewController](https://iosdevcenters.blogspot.com/2017/08/how-to-share-content-with.html) – MadProgrammer Oct 29 '18 at 05:34
1 Answers
0
Try somethings like this:
private func shareWhatYouWant() {
//pop invite view
var textToShare = "Your message"
if let myWebsite = NSURL(string: "Yourwebsite.com") {
let objectsToShare = [textToShare, myWebsite] as [Any]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
//New Excluded Activities Code
activityVC.completionWithItemsHandler = {
activity, sucess, items, error in
if !sucess {
print("cancelled")
return
}
if activity == UIActivityType.postToFacebook {
print("share on facebook")
}
if activity == UIActivityType.postToTwitter {
print("share on twitter")
}
if activity == UIActivityType.message {
print("share on message")
}
if activity == UIActivityType.addToReadingList {
print("air drop select")
}
}
activityVC.popoverPresentationController?.sourceView = sender as? UIView
self.present(activityVC, animated: true, completion: nil)
}
}

Gabriel
- 121
- 1
- 12