将Flutter App的iOS部分连接到Firebase的混乱

时间:2018-10-15 01:43:51

标签: ios swift firebase flutter

我正在尝试将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提供的代码替换现有代码,还是以某种方式协调两者?

2 个答案:

答案 0 :(得分:1)

在给定的(预定义)AppDelegate类中,您需要另外做两件事。 他们是

  1. import Firebase
    
  2. 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)
    }
}