我正在尝试将Flutter应用的iOS部分连接到Firebase。在Firebase上执行“ 将Firebase添加到您的iOS应用”中的步骤时,我遇到了一个步骤,说“ 将以下初始化代码添加到您的主AppDelegate类中 ”(快速版本):
import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)
-> Bool {
FirebaseApp.configure()
return true
}
}
但是我的AppDelegate类已经有了以下代码:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
不确定该怎么做。我该用Firebase提供的代码替换现有代码,还是以某种方式协调两者?
答案 0 :(得分:1)
在给定的(预定义)AppDelegate
类中,您需要另外做两件事。
他们是
import Firebase
FirebaseApp.configure()
答案 1 :(得分:1)
将两个代码合并在一起:
import UIKit
import Flutter
import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
FirebaseApp.configure()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}