Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift中使用Facebook Messenger SDK_Ios_Objective C_Facebook_Swift_Facebook Messenger - Fatal编程技术网

Ios 在Swift中使用Facebook Messenger SDK

Ios 在Swift中使用Facebook Messenger SDK,ios,objective-c,facebook,swift,facebook-messenger,Ios,Objective C,Facebook,Swift,Facebook Messenger,我一直在尝试在我的Swift项目中使用Facebook Messenger SDK。 问题是Facebook只展示了如何在Objective-C中使用。 我无法从FBSDKMessengerShareKit调用方法。 我制作了桥接头并添加了FBSDKMessengerShareKit以便导入。 桥接头是这样的 #import <FBSDKCoreKit/FBSDKCoreKit.h> #import <FBSDKLoginKit/FBSDKLoginKit.h> #imp

我一直在尝试在我的Swift项目中使用Facebook Messenger SDK。 问题是Facebook只展示了如何在Objective-C中使用。 我无法从FBSDKMessengerShareKit调用方法。 我制作了桥接头并添加了FBSDKMessengerShareKit以便导入。 桥接头是这样的

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

#ifndef myProject_Bridging_Header_h
#define myProject_Bridging_Header_h

#endif
我把它改成Swift的方式

if (FBSDKMessengerSharer.messengerPlatformCapabilities() & FBSDKMessengerPlatformCapability.Image) {
            let myImage = UIImage(named: "myImage")
            FBSDKMessengerSharer.shareImage(myImage, withOptions: nil)
}
我的Swift代码无法生成,它总是显示错误 “找不到接受所提供参数的“&”的重载”


我不知道我的Swift代码有什么问题,有人知道如何在Swift中使用Messenger SDK吗?

以下是您需要的代码:

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://itunes.apple.com/us/app/facebook-messenger/id454638411?mt=8")!)
    }

查看此项了解更多参考信息:

在Swift中,您可以使用以下代码:

            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: "https://itunes.apple.com/pl/app/messenger/id454638411?mt=8")!)
            }

这是一个显示内容的Messenger窗口。

不是答案,但从2021年4月15日起,
MessageDialog
FBSDKMessageDialog
已被弃用 这是FB

将不再支持共享到Messenger SDK,该SDK允许用户将应用程序中的链接和媒体共享到Messenger。企业和开发人员可能需要对其应用程序进行修改,以触发本机操作系统共享。人们将能够使用内置在设备中的本机共享功能向Messenger共享内容


Messenger PlatformCapabilities()与iOS 9iOS一样被抹黑。令人震惊的是,像Facebook这样的大型科技公司在其swift SDK上几乎没有文档。我知道他们的工程师是用Obj C编写代码的,但是如果你想费心制作一个swift SDK,那么就好好记录它。
            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: "https://itunes.apple.com/pl/app/messenger/id454638411?mt=8")!)
            }