You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复iOS端Facebook登录报错:‘登录错误,登录此应用时出现问题’?

iOS端React Native Facebook登录问题解决方案(适配RN 0.66.5)

1. 检查Info.plist核心配置

确保iOS项目的Info.plist中添加以下必填项:

  • 配置Facebook应用信息:
    <key>FacebookAppID</key>
    <string>你的应用ID</string>
    <key>FacebookDisplayName</key>
    <string>你的应用名称</string>
    
  • 添加URL白名单:
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>fbapi</string>
      <string>fbauth2</string>
      <string>fbshareextension</string>
    </array>
    
  • 配置回调URL Scheme:
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>fb你的应用ID</string>
        </array>
      </dict>
    </array>
    

2. 修复Pod依赖兼容性

进入iOS目录执行以下命令,确保依赖完全适配:

pod deintegrate
pod install --repo-update

建议锁定react-native-fbsdk版本为3.0.0,该版本对RN 0.60+系列兼容性较好。

3. 处理iOS 14+跟踪权限

iOS 14及以上系统需要主动申请跟踪权限,在Info.plist添加权限说明:

<key>NSUserTrackingUsageDescription</key>
<string>需要获取设备信息以完成Facebook登录验证</string>

并在登录前主动请求权限:

import { requestTrackingPermissions } from 'react-native-fbsdk';

const prepareLogin = async () => {
  const { status } = await requestTrackingPermissions();
  if (status === 'granted') {
    // 执行Facebook登录逻辑
  }
};

4. 验证AppDelegate回调配置

  • Objective-C版本(AppDelegate.m):
    #import <FBSDKCoreKit/FBSDKCoreKit.h>
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
      return YES;
    }
    
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
      BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options];
      return handled || [super application:application openURL:url options:options];
    }
    
  • Swift版本(AppDelegate.swift):
    import FBSDKCoreKit
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
      ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
      return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
      let handled = ApplicationDelegate.shared.application(app, open: url, options: options)
      return handled || super.application(app, open: url, options: options)
    }
    

5. 核对Facebook开发者后台设置

  • 确认iOS平台的Bundle ID与项目CFBundleIdentifier完全一致
  • 添加测试设备的UDID到后台测试设备列表
  • 确保已开启public_profile、email等必要的登录权限

内容的提问来源于stack exchange,提问作者Vova Ivaniuk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 02:15:40