Share text

@IBAction func shareText(_ sender: UIButton) {
    let text = "Your text"
    let textShare = [ text ]
    let activityVC = UIActivityViewController(activityItems: textShare , applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.view 
    self.present(activityVC, animated: true, completion: nil)
}

Share image

@IBAction func shareImage(_ sender: UIButton) {
    let image = UIImage(named: "Image")
    let imageShare = [ image! ]
    let activityVC = UIActivityViewController(activityItems: imageShare , applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.view 
    self.present(activityVC, animated: true, completion: nil)
}

Share text + image + url

@IBAction func shareAll(_ sender: UIButton) {
    let text = "Your text"
    let image = UIImage(named: "Image")
    let yourUrl = NSURL(string:"http://vncode247.com")
    let shareAll= [text , image! , yourUrl]
    let activityVC = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.view 
    self.present(activityViewController, animated: true, completion: nil)
}

 

Categories: iOS Tips

Leave a Reply

Your email address will not be published. Required fields are marked *