skip to Main Content

I am not able to access Firebase App Check. I am developing an application on SwiftUI and decided to connect App Attest . In FireBase console I registered my app and its status says “Registered” . I have written for connection in AppDelegate

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

When I run the app on a real phone via Xcode, the console shows this message

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"

and I can’t use it. I rechecked all the Data in Firebase and everything is correct. What do I need to do ?

2

Answers


  1. In your Xcode console logs I see that DeviceCheck was getting used (it’s the default). The call to AppCheck.setAppCheckProviderFactory(...) needs to happen before calling FirebaseApp.configure() in order to get applied.

    In your provided snippet, this would look like:

    let providerFactory = YourAppCheckProviderFactory()
    AppCheck.setAppCheckProviderFactory(providerFactory)
    
    FirebaseApp.configure()
    

    For the Debug Provider (usable on a simulator or a real phone for testing), this would be:

    let providerFactory = AppCheckDebugProviderFactory()
    AppCheck.setAppCheckProviderFactory(providerFactory)
    
    FirebaseApp.configure()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search