Search code examples
iosobjective-cfacebookfacebook-ios-sdkxcode-storyboard

Unknown class FBSDKLoginButton in Interface Builder file


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.


Solution

  • 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;
    }