Error: use of undeclared identifier 'FBSDKApplicationDelegate'

3.1k Views Asked by At

I installed react-native-fbsdk-next. Followed configuration steps. Wanted to build app on iOS (as usual). I am getting an error: use of undeclared identifier 'FBSDKApplicationDelegate' and the app won't build.

The error:

error information

My AppDelegate.mm:

#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <react-native-splash-screen/RNSplashScreen.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"AppName";
  self.initialProps = @{};

  bool didFinish=[super application:application didFinishLaunchingWithOptions:launchOptions];
  [RNSplashScreen show];
  [[FBSDKApplicationDelegate sharedInstance]application:application
    didFinishLaunchingWithOptions:launchOptions];
  return didFinish;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

- (BOOL)concurrentRootEnabled
{
  return true;
}


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

@end

Specification package.json and Podfile.lock:

"react": "18.2.0",
"react-native": "0.71.2",
"react-native-fbsdk-next": "^11.2.0",

  - FBAEMKit (15.0.0):
    - FBSDKCoreKit_Basics (= 15.0.0)
  - FBLazyVector (0.71.2)
  - FBReactNativeSpec (0.71.2):
    - RCT-Folly (= 2021.07.22.00)
    - RCTRequired (= 0.71.2)
    - RCTTypeSafety (= 0.71.2)
    - React-Core (= 0.71.2)
    - React-jsi (= 0.71.2)
    - ReactCommon/turbomodule/core (= 0.71.2)
  - FBSDKCoreKit (15.0.0):
    - FBAEMKit (= 15.0.0)
    - FBSDKCoreKit_Basics (= 15.0.0)
  - FBSDKCoreKit_Basics (15.0.0)
  - FBSDKGamingServicesKit (15.0.0):
    - FBSDKCoreKit (= 15.0.0)
    - FBSDKCoreKit_Basics (= 15.0.0)
    - FBSDKShareKit (= 15.0.0)
  - FBSDKLoginKit (15.0.0):
    - FBSDKCoreKit (= 15.0.0)
  - FBSDKShareKit (15.0.0):
    - FBSDKCoreKit (= 15.0.0)

Info.plist config: (ID is a number of course)

<dict>
...
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>fbID</string>
        </array>
      </dict>
    </array>
    <key>FacebookAppID</key>
    <string>ID</string>
    <key>FacebookDisplayName</key>
    <string>AppName</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>fbapi</string>
      <string>fb-messenger-share-api</string>
      <string>fbauth2</string>
      <string>fbshareextension</string>
    </array>
</dict>

I tried to switch #import <FBSDKCoreKit/FBSDKCoreKit.h> into #import <FBSDKCoreKit/FBSDKCoreKit-Switch.h> the app build but I was unable to open the app - crash. I also tried to fix it by deleting the pods, deleting the derived data and uninstallation of the app in the emulator.

3

There are 3 best solutions below

0
On BEST ANSWER

The problem was that parts of the react-native-fbsdk-next package have Swift code. Adding this code to post_install pods fixes the problem.

installer.aggregate_targets.first.user_project.native_targets.each do |target|
    target.build_configurations.each do |config|
        config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(inherited)', '$(SDKROOT)/usr/lib/swift']
    end
end
0
On

https://github.com/thebergamo/react-native-fbsdk-next/issues/317#issuecomment-1264750053

#import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>

Added this line of code fix this error.

0
On

Replace

#import <FBSDKCoreKit/FBSDKCoreKit.h>

to

#import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>