How To Share Content With UIActivityViewController - Swift 3.0

The UIActivityViewController release iOS6 and later. The UIActivityViewController that offer to use the various services from the App. The Services like copying item to the pasteboard , Share content on social media , Send item via email or SMS and More. 




We are provide the code to set content and attach images. The excludedActivityTypes which use to remove apps from 
UIActivityViewController and its optional.


Share : Text  
@IBAction func shareOnlyText(_ sender: UIButton) {
        let text = "iOSDevCenter have best tutorials of swift"
        let textShare = [ text ]
        let activityViewController = UIActivityViewController(activityItems: textShare , applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view 
        self.present(activityViewController, animated: true, completion: nil)
    }
 }

Share : Image 

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

Share : Text - Image - URL 

 @IBAction func shareAll(_ sender: UIButton) {
        let text = "iOSDevCenter have best tutorials of swift"
        let image = UIImage(named: "Image")
        let myWebsite = NSURL(string:"https://iosdevcenters.blogspot.com")
        let shareAll= [text , image! , myWebsite]
        let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view 
        self.present(activityViewController, animated: true, completion: nil)
  }

How To Share Using Social Framework.


Thanks.
How To Share Content With UIActivityViewController - Swift 3.0 How To Share Content With UIActivityViewController - Swift 3.0 Reviewed by Kirit Modi on 12:28:00 Rating: 5

No comments:

Powered by Blogger.