Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion connecting iOS portion of Flutter App to Firebase

I'm attempting to connect the iOS portion of my Flutter app to Firebase. And as I go through the steps on Firebase - "Add Firebase to your iOS app" - I hit a step that says "Add the initialization code below to your main AppDelegate class" (Swift version):

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
  }
}

But my AppDelegate class already has this code:

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)
  }
}

Not sure what to do. Do I replace the existing code with the code provided by Firebase or do I reconcile the two somehow?

like image 314
eggroll Avatar asked Oct 15 '18 01:10

eggroll


2 Answers

In the given (predefined) AppDelegate class, there are 2 things you need to do additionally. They are

import Firebase  // <-- 1st add

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
    ) -> Bool {
        GeneratedPluginRegistrant.register(with: self)

        FirebaseApp.configure() // <-- 2nd add

        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}
like image 56
CopsOnRoad Avatar answered Nov 05 '22 16:11

CopsOnRoad


Merge both code together:

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)
    }
}
like image 37
Zaid M. Said Avatar answered Nov 05 '22 15:11

Zaid M. Said