How to share a link on Facebook Messenger from other apps?

5.6k views Asked by At

From Facebook Developer Documentation, I see that I can share image, animated image, even audio clips from other app to Facebook Messenger. But I can see no way to share a link. Neither does when I try to look what kind of share does the FBSDKMessengerShare offer.

enter image description here

How can I share a link using Facebook Messenger?

1

There are 1 answers

1
David Steppenbeck On BEST ANSWER

Seems that it can't be done with FBSDKMessengerShare, but with FBSDKShareKit it's possible. (I'm using Xcode 8.3, Swift 3.1, Cocoapods with FacebookShare 0.2.0)

More info available at https://developers.facebook.com/docs/sharing/ios

There are two methods:

  1. Using FBSDKMessageDialog: "The Message Dialog switches to the native Messenger for iOS app, then returns control to your app after a post is published."

    @IBAction func messengerButtonAction(_ sender: UIButton) {
    
        let linkContent = FBSDKShareLinkContent()
        linkContent.contentURL = URL(string: "https://itunes.apple.com/in/app/someValidAppURL...")
    
        let dialog = FBSDKMessageDialog()
        dialog.shareContent = linkContent
        dialog.shouldFailOnDataError = true
    
        if dialog.canShow() {
            dialog.show()
        }
    }
    
  2. Using FBSDKSendButton: "The Send button lets people privately send photos, videos and links to their friends and contacts using the Facebook Messenger. The Send button will call a Message dialog."

    This creates a share button that is displayed in a specified view. The button will be automatically disabled if the Messenger app is not installed on the device.

    override func viewDidLoad() {
    
        let linkContent = FBSDKShareLinkContent()
        linkContent.contentURL = URL(string: "https://itunes.apple.com/in/app/someValidAppURL...")
    
        let button = FBSDKSendButton()        
        button.shareContent = linkContent      
        if button.isEnabled { 
           self.view.addSubview(button) 
        }
    }