Website Links

Monday 26 March 2018

Swift 4 - How to share messages and images

There are many benefits of enabling sharing within your application:
  • Free advertising for your app if users share from it on social media
  • Better user experience
  • Using recent iOS features to make the app feel more modern
The code for this is simple, when an event occurs that you would like to share on, you can call the following method:

  func share(_ message: String , shareImage: UIImage) {
    let share = [message, shareImage] as [Any]
    let activityViewController = UIActivityViewController(
      activityItems: share, applicationActivities: nil)
    activityViewController.popoverPresentationController?
      .sourceView = self.view
    self.present(activityViewController, animated: true, 
      completion: nil)
  }

No comments:

Post a Comment