应用程序在使用Firebase Auth时崩溃,原因是:"默认应用程序已配置完毕."

Bre*_*rdo 34 ios firebase swift firebase-authentication

我正在构建我的第一个iOS应用程序,我使用Firebase来处理身份验证,数据库等.我添加了一个注册屏幕,并使用以下代码创建一个新用户:

FIRAuth.auth()?.createUserWithEmail(emailAddress.text!, password: password.text!, completion: { (user, error) in

        })
Run Code Online (Sandbox Code Playgroud)

当用户点击注册按钮时,会有一个segue应该将它们带回原始登录视图控制器.但是,当我运行应用程序时,它会挂起启动屏幕.这是调试器输出:

2016-06-19 14:35:05.402 unitaskr[4386:82981] Configuring the default app.
2016-06-19 14:35:05.413 unitaskr[4386:] <FIRAnalytics/INFO> Firebase Analytics     v.3200000 started
2016-06-19 14:35:05.414 unitaskr[4386:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ...)
2016-06-19 14:35:05.419: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-06-19 14:35:05.418 unitaskr[4386:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-06-19 14:35:05.430 unitaskr[4386:82981] *** Terminating app due to uncaught exception 'com.firebase.core', reason: 'Default app has already been configured.'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001100a8d85   __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001108e7deb objc_exception_throw + 48
2   CoreFoundation                      0x00000001100a8cbd +[NSException raise:format:] + 205
3   unitaskr                            0x000000010b58844d +[FIRApp    configureDefaultAppWithOptions:sendingNotifications:] + 102
4   unitaskr                            0x000000010b588238 +[FIRApp configure] + 302
5   unitaskr                            0x000000010b541f1a _TFC8unitaskr11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryCSo8NSObjectPs9AnyObject____Sb + 266
6   unitaskr                            0x000000010b542204 _TToFC8unitaskr11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryCSo8NSObjectPs9AnyObject____Sb + 180
7   UIKit                               0x000000010e5bf9ac -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
8   UIKit                               0x000000010e5c0c0d -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3415
9   UIKit                               0x000000010e5c7568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
10  UIKit                               0x000000010e5c4714 -[UIApplication workspaceDidEndTransaction:] + 188
11  FrontBoardServices                  0x00000001127b78c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
12  FrontBoardServices                  0x00000001127b7741 -[FBSSerialQueue _performNext] + 178
13  FrontBoardServices                  0x00000001127b7aca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
14  CoreFoundation                      0x000000010ffce301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15  CoreFoundation                      0x000000010ffc422c __CFRunLoopDoSources0 + 556
16  CoreFoundation                      0x000000010ffc36e3 __CFRunLoopRun + 867
17  CoreFoundation                      0x000000010ffc30f8 CFRunLoopRunSpecific + 488
18  UIKit                               0x000000010e5c3f21 -[UIApplication _run] + 402
19  UIKit                               0x000000010e5c8f09 UIApplicationMain + 171
20  unitaskr                            0x000000010b542a42 main + 114
21  libdyld.dylib                       0x00000001113b692d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
Run Code Online (Sandbox Code Playgroud)

我可以根据需要提供更多信息,我会非常感激任何帮助/建议,因为我刚刚开始并希望尽可能多地学习.祝你有美好的一天!

Chr*_*lot 46

我有一个消息扩展的问题:

如果您在App扩展中,则没有委托,您必须将FIRApp.configure()放在主ViewController的init中(或者根据建议放在viewDidLoad中).

问题是:在消息扩展中,如果用户在打开扩展的线程中按下几条消息,init(或viewdidLoad)将被多次调用,因此由于多次调用FIRApp.configure()而崩溃...

我找到的解决方案是在主View Controller中创建一个静态bool:

    static var isAlreadyLaunchedOnce = false // Used to avoid 2 FIRApp configure
Run Code Online (Sandbox Code Playgroud)

我在init或viewDidLoad中调用FIRApp.configure()之前测试它:

// Configure Firebase
    // ------------------
    // We check if FIRApp has already been configured with a static var, else it will crash...
    if !MessagesViewController.isAlreadyLaunchedOnce {
        FIRApp.configure()

        MessagesViewController.isAlreadyLaunchedOnce = true
    }
Run Code Online (Sandbox Code Playgroud)

这样,不再崩溃.


哦,我找到了一个更优雅的方法来解决这个问题: iOS扩展 - 致命异常:com.firebase.core默认应用程序已经配置

    // Configure Firebase
    // ------------------
    if FIRApp.defaultApp() == nil {
        FIRApp.configure()            
    }
Run Code Online (Sandbox Code Playgroud)

这种方式不再是静态的;)

  • 这很好.在扩展上下文中使用它. (2认同)
  • if FirebaseApp.app() == nil { FirebaseApp.configure() } (2认同)

Bre*_*rdo 27

我写了FIRApp.configure()两次,似乎修复了错误.


小智 11

这是关于此问题的其他解决方案.1 /检查"AppDelegate.swift",我们将在下面看到

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    return true
}
Run Code Online (Sandbox Code Playgroud)

2 /从上面的代码中删除"FirebaseApp.configure()"

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    return true
}
Run Code Online (Sandbox Code Playgroud)

3 /将以下代码添加到"AppDelegate.swift"中

override init() {
    FirebaseApp.configure()
}
Run Code Online (Sandbox Code Playgroud)

4 /转到"ViewController.swift"并添加代码

    if FirebaseApp.app() == nil {
        FirebaseApp.configure()
    }
Run Code Online (Sandbox Code Playgroud)

5 /再次构建并运行它将起作用.谢谢!


Pri*_*ati 7

类名称:AppDelegate + FCMPlugin.m

[FIRApp.configure()];

将此放在此方法的最顶部

- (BOOL)application:(UIApplication *)application customDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 if(![FIRApp defaultApp]){
    [FIRApp configure];}}
Run Code Online (Sandbox Code Playgroud)


sso*_*ri1 7

对于 Swift 4,

if FirebaseApp.app() == nil {
/// code snippet
}
Run Code Online (Sandbox Code Playgroud)


Our*_*han 6

您可以在AppDelegate init方法中调用一次进行配置.

override init() {
   // Firebase Init
   FIRApp.configure()
}
Run Code Online (Sandbox Code Playgroud)

  • `override func viewDidLoad(){super.viewDidLoad()FIRApp.configure()}`//这是我在我的Keyboard扩展UIInputViewController类中编写的.但是当我将键盘切换到Native ios键盘并再次切换到我的键盘时,这个方法被调用并且崩溃发生了这个**错误 - [原因:'默认应用已经配置.']** (2认同)

Ian*_*hao 5

以防万一其他人偶然发现这个问题。当使用firebasesdk与googleSignInsdk时。您只需配置一次。要么做 [[GGLContext sharedInstance] configureWithError: &configureError]; 要么 [FIRApp configure]


Mih*_*ari 5

如果您使用的是 Scene delegate,并且您有不同的 iOS 版本(例如 9、10 到 13) ,则必须以这种方式调用AppDelegate.swift :

 if #available(iOS 13.0, *) {
 
 } else {
     FirebaseApp.configure()
 }
Run Code Online (Sandbox Code Playgroud)

SceneDelegate.swift中这样:

 if #available(iOS 13.0, *) {
   FirebaseApp.configure()
 }
Run Code Online (Sandbox Code Playgroud)

这些设置将排除如下错误:*

*** 由于未捕获的异常“com.firebase.core”而终止应用程序,原因:“默认应用程序已配置。”


Abi*_*san 5

这是我的代码AppDelegate.swift

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)
  }
}
Run Code Online (Sandbox Code Playgroud)

您可以删除这个FirebaseApp.configure()或添加

 if #available(iOS 13.0, *) {
 
 } else {
     FirebaseApp.configure()
 }
Run Code Online (Sandbox Code Playgroud)

两者都为我工作


小智 5

这是因为您已经在 AppDelegate 中 初始化了FirebaseApp.configure() 。请确保仅配置一次并且错误应该消失。