iOS Project Configuration

This topic assumes that you have already created a React Native project using React Native version 0.60 or greater. If you haven't, then visit Getting Started with the Facebook SDK for React Native.

Configure the Facebook SDK for iOS

At this point, you have installed the Facebook SDK for React Native, but you still must perform additional steps to install and configure the native Facebook SDK for iOS.

The iOS project file is located in the iOS folder at [YourApp]/ios/[YourApp].xcodeproj. Open your iOS project in Xcode, then follow the Quickstart for the Facebook SDK for iOS to complete the process.

Important: In the Quickstart Guide, skip the steps that instruct you to run pod install.

Along with FBSDKCoreKit.framework, do not forget to import FBSDKShareKit.framework and FBSDKLoginKit.framework into your Xcode project.

Test Your Application

At this point, your application should be fully configured and ready to run. To test it, you can run it in Xcode or from a command prompt. To run it from a command prompt, navigate to your application folder and type:

react-native run-ios

If everything is working correctly, you will see a terminal window appear. This window hosts the Metro server process that delivers your JavaScript code to the emulator. After that, you will also see your application start inside the emulator.

Troubleshooting

I get a build error stating that one of the Facebook SDK files was not found:

Example: FBSDKLoginKit/FBSDKLoginKit.h file not found.

  • Make sure that the Facebook SDK frameworks are installed in `~/Documents/FacebookSDK`.
  • Make sure that FBSDKCoreKit.framework, FBSDKLoginKit.framework, and FBSDKShareKit.framework all show up in the "Link Binary with Libraries" section of your build target's Build Phases.

  • Make sure that ~/Documents/FacebookSDK is in the Framework Search Path of your build target's Build Settings. You may have to select the All tab to see and search for the Framework Search Path.

I get build errors like Warning: Native component for "RCTFBLikeView" does not exist:

  • Make sure that libRCTFBSDK.a shows up in the Link Binary with Libraries section of your build target's Build Phases.

I get this build error: no type or protocol named UIApplicationOpenURLOptionsKey:

  • Your Xcode version is too old. Upgrade to Xcode 10.0+.

Could not connect to the development server:

If you get an application error on your emulator that says, "Could not connect to the development server," then your Metro server is not running. In that case, open a command prompt in your application folder and type:

yarn start

Leave this window open, and leave the server running while you test and debug your application.

If you are using RCTLinkingManager:

The AppDelegate.m file can only have one method for openUrl. If you're also using RCTLinkingManager to handle deep links, you should handle both results in your openUrl method:

- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
    return YES;
  }

  if ([RCTLinkingManager application:app openURL:url options:options]) {
    return YES;
  }

  return NO;
}

If you cannot run the iOS project, then make sure that you have completed the instructions in the Configure the Facebook SDK for iOS section above. You may also want to take a look at the React Native Facebook SDK instructions on GitHub for additional troubleshooting help and examples.