Swift3使用Firebase遇FIRAppNotConfigured异常,寻求解决办法
FIRAppNotConfigured Error in Firebase iOS Setup Hey there, let's work through this FIRAppNotConfigured error step by step—this is a super common snag when getting started with Firebase, so we'll get your app up and running in no time.
Here are the key fixes to check:
Ensure
FIRApp.configure()is called before accessing Firebase services
The error message spells it out clearly: you need to initialize Firebase before using any of its tools (likeFIRDatabase). For traditional UIKit apps, add this call in yourAppDelegate's launch method:func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Initialize Firebase FIRST FIRApp.configure() // Rest of your app setup code return true }If you're using SwiftUI, place the initialization in your app's root struct:
@main struct YourTutorialApp: App { init() { FIRApp.configure() } var body: some Scene { WindowGroup { ContentView() } } }Double-check that this line isn't buried after code that tries to access Firebase Database—order matters here!
Verify your
GoogleService-Info.plistis properly added
Even if you dragged the file into Xcode, it might not be linked to your target:- Select the
GoogleService-Info.plistfile in Xcode's project navigator. - Look at the right-hand sidebar (Inspector) and check the Target Membership section. Make sure your main app target is checked.
- Confirm the filename is exactly
GoogleService-Info.plist(capitalization and spelling count!). - If you're using the tutorial's final project, remember: you need to replace the included plist with your own (downloaded from your Firebase console, linked to your project). The tutorial's plist is tied to the author's Firebase project and won't work for your setup.
- Select the
Clean up build artifacts and dependencies
Sometimes cached data causes unexpected issues:- Press
Command + Shift + Kto clean your Xcode build folder. - If you're using CocoaPods, run
pod installagain in your project directory to ensure all Firebase dependencies are properly installed. Double-check your Podfile includes bothpod 'Firebase/Core'andpod 'Firebase/Database'.
- Press
Double-check Keychain Sharing setup
While this error is mostly about Firebase initialization, confirm that Keychain Sharing is enabled in your project's Signing & Capabilities tab. Make sure your team's keychain group is added (it should match theCLIENT_IDin your plist file).
If you work through these steps, you should eliminate the FIRAppNotConfigured error. Start with the first two checks—they're the most likely culprits!
内容的提问来源于stack exchange,提问作者ema so

