-2

Can I add or change UIActivityViewController into this code .

  func ShareBu (_ sender: AnyObject) {

    let shareToFacebook : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)

          shareToFacebook.setInitialText(mydata[sender.tag].Desc)
           shareToFacebook.add(URL(string : self.mydata [sender.tag].ImgURL))
           self.present(shareToFacebook, animated: true, completion: nil)


}
  • Can you help me here ? @Rajat – Zaid Mustafa Nov 20 '16 at 07:07
  • Please make your question more clear. – Dharmesh Kheni Nov 20 '16 at 07:17
  • When I press the share button its directly going to Facebook , I want to add UIActivityViewController to choose where I want to make the share . @Dharmesh Kheni – Zaid Mustafa Nov 20 '16 at 07:22
  • Please add all details in the question, not in comments. Try to make people who have no idea what you're coding understand clearly what's the problem. It will make it easier to get the help you need. If you want some guideline, check this: [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) – Tom Nov 20 '16 at 09:28

1 Answers1

1

Here you go:

@IBAction func shareButtonClicked(sender: UIButton) {
    let textToShare = "Swift is awesome!  Check out this website about it!"

    if let myWebsite = NSURL(string: "http://www.codingexplorer.com/") {
        let objectsToShare = [textToShare, myWebsite] as [Any]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

        activityVC.popoverPresentationController?.sourceView = sender
        self.present(activityVC, animated: true, completion: nil)
    }
}

Check this for more INFO.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165