I'm developing a flutter application which uses Firebase as it's back-end framework. I've been developing the application for Android for quite some time, and recently I'm trying to support iOS as well. In my application, I do a call to Firebase RTDB to get some data, and I used await for it since I need it to be finished before performing other tasks. However, the fetch operation never finishes when I open it on iOS Simulator, it works fine when I use it in the distributed app on a real device. This didn't happen before I enforced App Check for my Firebase Project. Which convinces me that this problem is due to App Check. So I looked up on how to register my debug environment, which is provided here in the Firebase Docs. But, even after following the steps, I still can't get the debug token to show up in the terminal. Are there any steps that I might've missed? Any help would be greatly appreciated! Thanks.
2 Answers
I found an ostensible solution for testing on the iOS simulator when building out a native SwiftUI app. I assume you need to add some Swift code when building out AppCheck within Flutter. In the custom AppCheckProviderFactory
that gets created for when the app check gets launched, you'll want to add some custom code to print out the localDebugToken
of the simulator. Then, you'll store that in the device tokens under AppCheck in Firebase.
import Foundation
import FirebaseCore
import FirebaseAppCheck
class NativeAppCheckProviderFactory: NSObject, AppCheckProviderFactory {
func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
#if targetEnvironment(simulator)
// App Attest is not available on simulators.
// Use a debug provider.
let provider = AppCheckDebugProvider(app: app)
// Print only locally generated token to avoid a valid token leak on CI.
print("Firebase App Check debug token: \(provider?.localDebugToken() ?? "" )")
return provider
#else
// Use App Attest provider on real devices.
return AppAttestProvider(app: app)
#endif
}
}

- 3,119
- 19
- 19
- 37

- 31
- 7
The solution that I found was that the debug token won't show up if I run it directly from Android Studio, however, if I run it using Xcode, it shows up. So I always use Xcode for the first run to register the debug token, after that I just proceed on using Android Studio as the debug token has been registered.

- 131
- 7