错误:使用未声明的标识符“FBSDKApplicationDelegate”

问题描述 投票:0回答:3

我安装了

react-native-fbsdk-next
。 遵循配置步骤。 想要在 iOS 上构建应用程序(像往常一样)。我收到了
error: use of undeclared identifier 'FBSDKApplicationDelegate' and the app won't build.

错误:

我的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

规范package.json和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配置:(ID当然是数字)

<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>

我尝试过切换

#import <FBSDKCoreKit/FBSDKCoreKit.h>
进入
#import <FBSDKCoreKit/FBSDKCoreKit-Switch.h>
应用程序构建,但我无法打开应用程序 - 崩溃。 我还尝试通过删除 Pod、删除派生数据以及卸载模拟器中的应用程序来修复它。

react-native fbsdk react-native-fbsdk react-native-fbsdk-next
3个回答

0
投票

问题在于,react-native-fbsdk-next 包的部分内容包含 Swift 代码。将此代码添加到 post_install pod 可以解决问题。

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
投票

更换

#import <FBSDKCoreKit/FBSDKCoreKit.h>

#import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>
© www.soinside.com 2019 - 2024. All rights reserved.