Interface Builder 文件中的未知 class FBSDKLoginButton

Unknown class FBSDKLoginButton in Interface Builder file

我的全新项目遇到了一个非常令人沮丧的构建问题。我正在尝试集成 Facebook iOS SDK,但由于某种原因,我遇到了一些奇怪的错误。尝试使用 FBSDKLoginKit 在故事板视图上显示 FBSDKLoginButton 时。

第一个提示是错误的 "error" 当我尝试 #import <FBSDKLoginKit/FBSDKLoginKit.h> 时(但它只在编辑器中显示为错误;它仍然可以正常编译):

"Could not build module FBSDKLoginKit."

奇怪的是,这个 "error" 在修改了一些与模块相关的构建设置后消失了,即使我将它们设置回原始值也是如此。

同样有趣的是,如果我从我的视图控制器中显式引用 FBSDKLoginButton class(例如以编程方式添加按钮),那么基于情节提要的实例化工作正常。所以我猜这一定是链接器问题或其他问题,但我承认我不是这方面的专家。

None 的 Facebook SDK 文档提到了我可以找到的这个问题,这很奇怪,因为正如我所说,这是一个全新的干净项目。

我的错,the documentation does mention this,并建议通过参考 application didFinishLaunchingWithOptions: 中的 FBSDKLoginButton class 来解决它,就像我已经想到的那样。 (坦率地说,你在哪里引用它并不重要,所以哪里感觉最舒服。对我来说,视图控制器更有意义。)

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [FBSDKLoginButton class];
    ...
    return YES;
}

对于 Swift 使用 FBSDKLoginButton.superclass()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    FBSDKLoginButton.superclass()

    return true
}