Flutter iOS应用Firebase手机认证报错:无法加载reCAPTCHA依赖
针对你遇到的[firebase_auth/web-internal-error] unable to load external reCAPTCHA dependencies错误,可按以下步骤排查修复:
核对Custom URL Scheme的正确性
你当前配置的是普通Client ID,但iOS端Firebase手机号认证要求的Custom URL Scheme必须是GoogleService-Info.plist中的REVERSED_CLIENT_ID值,而非常规Client ID。打开GoogleService-Info.plist找到该字段,替换掉当前Xcode中CFBundleURLSchemes里的内容。同时确保GoogleService-Info.plist已正确复制到Xcode项目目录(不是仅引用)。添加App Transport Security例外
在Info.plist中添加允许reCAPTCHA相关域名的网络权限,避免iOS拦截请求:<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <false/> <key>NSExceptionDomains</key> <dict> <key>google.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads</key> <false/> <key>NSExceptionRequiresForwardSecrecy</key> <true/> </dict> <key>recaptcha.net</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads</key> <false/> </dict> </dict> </dict>完善iOS端回调处理
在AppDelegate.swift中添加URL跳转回调逻辑,确保reCAPTCHA验证完成后能正确返回应用:import UIKit import Flutter import Firebase @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { FirebaseApp.configure() GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return ApplicationDelegate.shared.application(app, open: url, options: options) } }若使用SwiftUI,需通过
UIApplicationDelegateAdaptor适配上述逻辑。启用Associated Domains能力
在Xcode的Signing & Capabilities中添加Associated Domains,填入applinks:你的Firebase动态链接域名(可从Firebase控制台动态链接页面获取),确保reCAPTCHA验证后的跳转能被正确识别。清理缓存并重新构建
执行以下命令清理Flutter缓存:flutter clean flutter pub get再在Xcode中执行
Product -> Clean Build Folder,之后重新运行项目。检查依赖版本
确保pubspec.yaml中firebase_auth为最新稳定版,避免版本兼容问题:dependencies: firebase_auth: ^最新稳定版号
内容的提问来源于stack exchange,提问作者RitchyCZE

