Confusion connecting iOS portion of Flutter App to Firebase

3,429

Solution 1

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

Solution 2

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)
    }
}
Share:
3,429
eggroll
Author by

eggroll

Updated on December 07, 2022

Comments

  • eggroll
    eggroll over 1 year

    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?

  • Shalabyer
    Shalabyer about 3 years
    FirebaseApp.configure(), you can now safely remove it FlutterFire automatically handles this for you. firebase.flutter.dev/docs/migration/#b-ios-installation