配置默认 Firebase 应用 __FIRAPP_DEFAULT

Aar*_*sen 7 dart firebase firebase-authentication flutter flutter-dependencies

在遵循 flutter 教程示例以在 yaml 文件中添加 firebase 依赖项时,我会在控制台“配置默认 Firebase 应用 __FIRAPP_DEFAULT”中得到此打印输出:

 dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^0.4.0+6
  cloud_functions: ^0.4.0+2
  firebase_auth: ^0.11.1+7
  firebase_database: ^3.0.3
  firebase_storage: ^3.0.2
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Aar*_*sen 12

在我的特定工作流程中,添加 firebase 依赖项时,教程代码和颤振警告从未提示修改 AppDelegate.m 文件。直到我回拨并添加 cloud_firestore 才收到此警告提示:

6.3.0 - [Firebase/Core][I-COR000003] 尚未配置默认 Firebase 应用。添加【FIRApp配置】;(Swift 中的 FirebaseApp.configure())到您的应用程序初始化。

阅读更多:[ https://firebase.google.com/docs/ios/setup#initialize_firebase_in_your_app]

  1. 打开 xc 工作区 >> 打开 ios/Runner.xcworkspace
  2. 打开 AppDelegate.m
  3. 在 AppDelegate.m 中添加以下行:

导入 Firebase;

  1. 在 AppDelegate.m 中,将以下代码段添加到您的应用程序 did finish 方法中

【FIRApp配置】;

这是我最后的样子:

在此处输入图片说明

  • 步骤 3 和 4 有您需要的代码“import Firebase;” 和“[FIRApp 配置];”,该图像用于上下文。 (2认同)

And*_*ass 7

这对我有用: https://medium.com/vector-com-mm/how-to-fix-ios-crash-during-the-start-firebase-configure-f3477df3154

在 AppDelegate.swift 中更改顺序

GeneratedPluginRegistrant.register(with: self)
FirebaseApp.configure()
Run Code Online (Sandbox Code Playgroud)

到:

FirebaseApp.configure() 
GeneratedPluginRegistrant.register(with: self)
Run Code Online (Sandbox Code Playgroud)

清理并重建...

我的 AppDelegate.swift

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)
  }
}
Run Code Online (Sandbox Code Playgroud)