since iOS 6, Apple has provided the handy, but much-overlooked, UIActivityViewController
class.
first of all Create an instance of UIActivityViewController
and, for activityItems
, pass in a message or a URL or both to your app’s data file. Depending on the activity the user selects from the activity menu, iOS uses the message you pass in to pre-populate its content.
For example, if the user chooses to share the book via Email, the message you passed in will pre-populate the body of the email. Since not all activities have such capability, such as AirDrop, iOS may discard the message.
finally present
the UIActivityViewController
to the user.
let shareString = "Hello This is a sharingText!"
let shareUrl = URL(string: "https://www.google.com")
let activityViewController: UIActivityViewController = UIActivityViewController(activityItems: [shareString, shareUrl], applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil)