Unknown class FBSDKLoginButton in Interface Builder file

偶尔善良 提交于 2020-02-23 10:41:21

问题


I am experiencing a very frustrating build issue with my brand new project. I am trying to integrate Facebook iOS SDK, but for some reason I am getting some bizarre errors. When trying to use FBSDKLoginKit to display an FBSDKLoginButton on a storyboard view.

The first hint something is wrong is this "error" when I attempt to #import <FBSDKLoginKit/FBSDKLoginKit.h> (however it only appears as an error in the editor; it still compiles fine):

"Could not build module FBSDKLoginKit."

Strangely, this "error" went away after fiddling with some of the module-related build settings, even when I set them back to their original values.

Also interestingly, if I explicitly reference the FBSDKLoginButton class from my view controller (for example add the button programmatically), then storyboard-based instantiation works fine. So I'm guessing this must be some linker issue or something, but I'm admittedly not a pro at that stuff.

None of the Facebook SDK documentation mentions this issue that I can find, which is bizarre because like I said this is a brand new clean project.


回答1:


My bad, the documentation does mention this, and suggests solving it much as I already figured out, by referencing the FBSDKLoginButton class in application didFinishLaunchingWithOptions:. (Frankly it doesn't matter where you reference it, so wherever feels most comfortable. For me, the view controller makes more sense.)

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



回答2:


For Swift use FBSDKLoginButton.superclass()

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

    FBSDKLoginButton.superclass()

    return true
}


来源:https://stackoverflow.com/questions/30311246/unknown-class-fbsdkloginbutton-in-interface-builder-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!