Search code examples
iosswiftswift3

Sharing to social media that install on phone iOS Swift


Is there any specific method to share button that detect all social media apps on your iOS phone ?

example : my phone have whatsapp and twitter installed. so when I pressed share button only whatsapp and twitter came out, not facebook and any other apps not installed on my phone.

In android there's particular intent to use that kind of method. However in iOS I still can't find it.

Note : I need it for Swift 3 programmatically

Any help is very useful, Thank you


Solution

  • You should try this:

    @IBAction func shareImageButton(_ sender: UIButton) 
    {
    
        // image to share
        let image = UIImage(named: "Image")
    
        // set up activity view controller
        let imageToShare = [ image! ]
        let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
    
        // exclude some activity types from the list (optional)
        activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
    
        // present the view controller
        self.present(activityViewController, animated: true, completion: nil)
    }