Using Facebook Messenger SDK in Swift

I am trying to use Facebook Messenger SDK in my Swift Project. And the problem is that Facebook only shows how to use in Objective-C. I am having trouble calling methods from the FBSDKMessengerShareKit. I concatenated the header and added the FBSDKMessengerShareKit to import. The bridge header looks like this

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKMessengerShareKit/FBSDKMessengerShareKit.h>

#ifndef myProject_Bridging_Header_h
#define myProject_Bridging_Header_h



This is how Facebook shows you how to share an image on Messenger using Objective-C

if ([FBSDKMessengerSharer messengerPlatformCapabilities] & FBSDKMessengerPlatformCapabilityImage) {
    UIImage *image = [UIImage imageNamed:@"myImage];
    [FBSDKMessengerSharer shareImage:image withOptions:nil];


How I change it to Swift

if (FBSDKMessengerSharer.messengerPlatformCapabilities() & FBSDKMessengerPlatformCapability.Image) {
            let myImage = UIImage(named: "myImage")
            FBSDKMessengerSharer.shareImage(myImage, withOptions: nil)


My Swift code cannot be generated and it always shows the error "Could not find an overload for" & "that takes the supplied arguments"

I don't know what happened to my Swift code. Does anyone know how to use MessengerSDK in Swift?


source to share

2 answers

here is the code you need:

let result = FBSDKMessengerSharer.messengerPlatformCapabilities().rawValue & FBSDKMessengerPlatformCapability.Image.rawValue
    if result != 0 {
        // ok now share
        if let sharingImage = sharingImage {
            FBSDKMessengerSharer.shareImage(sharingImage, withOptions: nil)
    } else {
        // not installed then open link. Note simulator doesn't open iTunes store.
        UIApplication.sharedApplication().openURL(NSURL(string: "itms://")!)


Check it out for more help:



In Swift, you can use this code:

            if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb-messenger-api://")!) {
                let content = FBSDKShareLinkContent()
                content.contentURL = NSURL(string: url)
                content.contentTitle = "your awesome title"

                FBSDKMessageDialog.showWithContent(content, delegate: self)
            } else {
                UIApplication.sharedApplication().openURL(NSURL(string: "")!)


Displays a Messenger window with content.



All Articles