【问题标题】:When try to flutter run in iOS device, getting s6Runner11AppDelegateC11application尝试在 iOS 设备中颤振运行时,获取 s6Runner11AppDelegateC11application
【发布时间】:2020-08-13 01:04:26
【问题描述】:

我第一次尝试在 iOS (iPhone 8) 模拟器上使用命令 flutter cleanflutter run 运行 Flutter 应用程序。我收到以下错误:

Configuring the default Firebase app...
Configured the default Firebase app __FIRAPP_DEFAULT.
*** First throw call stack:
(
        0   CoreFoundation                      0x00007fff23e39f0e __exceptionPreprocess + 350
        1   libobjc.A.dylib                     0x00007fff50ad79b2 objc_exception_throw + 48
        2   CoreFoundation                      0x00007fff23e39d4c +[NSException raise:format:] + 188
        3   Runner                              0x0000000106f1d519 +[FIRApp appWasConfiguredTwice:usingOptions:] + 185
        4   Runner                              0x0000000106f1cf92 +[FIRApp configureWithName:options:] + 306
        5   Runner                              0x0000000106f1cd1f +[FIRApp configureWithOptions:] + 143
        6   Runner                              0x0000000106f1cc6d +[FIRApp configure] + 157
        7   Runner                              0x0000000106eb81a4 $s6Runner11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtF + 212
        8   Runner     <…>
This is taking longer than expected...

所以我怀疑该错误与我的“Firebase”依赖项有关。

1) 我的 podfile 如下:

  pod 'Flutter', :path => 'Flutter'
  pod 'Firebase/Analytics'
  pod 'Firebase/Auth'
  pod 'Firebase/Firestore'

2) 我确实看到我的 GoogleService-Info.plist 位于 /ios/Runner 下。

3) 我的AppDelegate.swfit如下:

import UIKit
import Flutter
import Firebase

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

我应该如何解决这个问题?

【问题讨论】:

    标签: ios firebase flutter


    【解决方案1】:

    您的日志输出开始于:

    Configuring the default Firebase app...
    Configured the default Firebase app __FIRAPP_DEFAULT.
    

    这来自 Flutter 插件,如果 Firebase 应用尚未初始化,它会尝试初始化它。

    之后会调用didFinishLaunchingWithOptions 方法,因此在使用Flutter 插件时,无需按照iOS SDK 文档中所述在didFinishLaunchingWithOptions 方法中配置Firebase 应用程序。

    所以删除AppDelegate.swift中的更改如下:

    import UIKit
    import Flutter
    import Firebase // Remove this line
    
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
      override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
      ) -> Bool {
        GeneratedPluginRegistrant.register(with: self)
        FirebaseApp.configure()  // Remove this line
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
      }
    }
    

    因为这令人困惑,它可能会在未来发生变化或有更好的文档,请观看https://github.com/FirebaseExtended/flutterfire/issues/2466

    【讨论】:

    • 但是... Firebase 根本没有配置
    • 好的,我收回,它仍然是......但是如何?
    • 我找到了。颤振插件似乎自己配置 Firebase 实例。参见例如 github.com/FirebaseExtended/flutterfire/blob/… 。由于某些原因,检查实例是否已配置的安全检查不起作用。见github.com/FirebaseExtended/flutterfire/issues/2466
    • 其实那是因为在插件init之后调用了native端的init。这是一个正确的答案,我已经对其进行了编辑以添加更多上下文
    猜你喜欢
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 2021-09-05
    • 2020-10-21
    • 2021-02-13
    • 2020-02-26
    相关资源
    最近更新 更多