iOS端Firebase App Check无法注册问题求助
解决Firebase App Check App Attest的"App not registered"错误
问题场景
开发SwiftUI iOS应用时接入Firebase App Check的App Attest功能,已在Firebase控制台完成应用注册(状态显示"Registered"),并在AppDelegate中配置了相关代码,但真机运行时控制台输出App not registered的400错误。
配置代码
class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { FirebaseApp.configure() let providerFactory = YourAppCheckProviderFactory() AppCheck.setAppCheckProviderFactory(providerFactory) UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in print("Permission granted: \(granted)") } application.registerForRemoteNotifications() return true } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { // 处理远程通知注册 Auth.auth().setAPNSToken(deviceToken, type: .unknown) } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { // 处理远程通知注册错误 print("Failed to register for remote notifications: \(error.localizedDescription)") } func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { // 处理收到的通知 if Auth.auth().canHandleNotification(userInfo) { completionHandler(.noData) return } } }
错误信息
UserInfo={NSLocalizedFailureReason=Too many attempts. Underlying error: Не удалось завершить операцию. The server responded with an error: - URL: https://firebaseappcheck.googleapis.com/v1/projects/xxxx/apps/xxxxx:exchangeDeviceCheckToken - HTTP status code: 400 - Response body: { "error": { "code": 400, "message": "App not registered: xxxxx", "status": "FAILED_PRECONDITION"
解决方案
- 核对Bundle ID完全匹配:确保Firebase控制台中注册的App Bundle ID,与Xcode项目
Info.plist里的CFBundleIdentifier完全一致,包括大小写,无拼写错误。 - 重新下载GoogleService-Info.plist:删除项目中旧的配置文件,从Firebase控制台重新下载最新版本,拖入Xcode时勾选对应Target,保证配置同步。
- 确认App Attest已启用:在Firebase控制台的App Check页面,检查App Attest提供者处于启用状态,仅注册App不足以激活该功能。
- 检查Provisioning Profile权限:在Apple开发者后台,确认对应Provisioning Profile已包含App Attest权限,若未包含则重新生成Profile。
- 清理缓存并重建项目:
- 删除Xcode的Derived Data:通过
Xcode > Preferences > Locations > Derived Data打开文件夹,删除当前项目的缓存文件。 - 执行
Cmd+Shift+K清理项目,再执行Cmd+Shift+Option+K清理构建文件夹。 - 卸载设备上的应用,重新运行。
- 删除Xcode的Derived Data:通过
- 验证AppCheckProviderFactory实现:确保自定义工厂类正确返回App Attest提供者,示例代码如下:
class YourAppCheckProviderFactory: NSObject, AppCheckProviderFactory { func createProvider(with app: FirebaseApp) -> AppCheckProvider? { return AppAttestProvider(app: app) } }
- 排查网络环境:关闭代理或防火墙,确保设备网络可以正常访问Firebase相关服务,避免请求被拦截。
内容的提问来源于stack exchange,提问作者AlenTi
相关产品推荐
相关产品推荐

