How To Share Content With Social Framework - Swift 3.0.

The Social framework is Supported iOS6 and later. Before the framework, The UIActivityViewController class is provide to sharing option to anywhere. Read about Social Framework.




To use the social framework we have to import in swift file. Add the below line in ViewController.swift file.
import Social

Twitter : Share With Image,Content and URL.
@IBAction func tweetButtonShare(_ sender: Any) {
    if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {

        let tweetShare = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
        if let tweetShare = tweetShare {
            tweetShare.setInitialText("Nice Tutorials of iOSDevCenters")
            tweetShare.add(UIImage(named: "iOSDevCenters.jpg")!)
            tweetShare.add(URL(string: "https://iosdevcenters.blogspot.com"))
            self.present(tweetShare, animated: true, completion: nil)
        }
    } else {
          print("Not Available")
    }
}

Facebook :  Share With Image,Content and URL.
@IBAction func facebookButtonShare(_ sender: Any) {
    if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook) {

        let facebookShare = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        if let facebookShare= facebookShare{
            facebookShare.setInitialText("Nice Tutorials of iOSDevCenters")
            facebookShare.add(UIImage(named: "iOSDevCenters.jpg")!)
            facebookShare.add(URL(string: "https://iosdevcenters.blogspot.com"))
            self.present(facebookShare, animated: true, completion: nil)
        }
    } else {
          print("Not Available")
    }
}

How To Share Using UIActivityViewController.

Thanks.


How To Share Content With Social Framework - Swift 3.0. How To Share Content With Social Framework - Swift 3.0. Reviewed by KIRIT MODI on 11:12:00 Rating: 5

No comments:

Powered by Blogger.