在使用Firebase Auth时,应用程序崩溃,原因是:“默认应用程序已经配置好了。”

时间:2023-01-22 15:15:23

I'm building my first iOS application, and I am using Firebase to handle authentication, database, etc. I added a sign up screen and used the following code to create a new user:

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

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

        })

When the user taps on the sign up button, there is a segue that should take them back to the original login view controller. However, when I got to run the app, it hangs on the launch screen. Here is the debugger output:

当用户点击注册按钮时,会有一个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) 

I can provide additional information as needed, any help/advice would be greatly appreciated as I am just starting out and looking to learn as much as possible. Have a great day!

我可以提供需要的额外信息,任何帮助/建议都将非常感谢,因为我刚刚开始,并期待尽可能多的学习。祝你有美好的一天!

6 个解决方案

#1


32  

I had a problem with a Messages Extension :

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

If you're in an App Extension, you have no delegate, and you'll have to put the FIRApp.configure() in the init of your main ViewController (or in the viewDidLoad as suggested).

如果你在一个应用程序扩展中,你没有委托,你必须把FIRApp.configure()放在主视图控制器的init中(或者像建议的那样放在viewDidLoad中)。

Problem is : in a Messages Extension, if the user presses several messages in the thread opening your extension, init (or viewdidLoad) will be called several times, therefore crashing due to FIRApp.configure() called several times...

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

The solution I found was to create a static bool in the main View Controller :

我找到的解决方案是在主视图控制器中创建一个静态bool:

    static var isAlreadyLaunchedOnce = false // Used to avoid 2 FIRApp configure

and I test it before calling FIRApp.configure() in the init or viewDidLoad :

在调用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
    }

This way, no more crashes.

这样,就不会再发生撞车事故了。


Oh, I found a much more elegant way to solve the problem here : iOS Extension - Fatal Exception: com.firebase.core Default app has already been configured

我找到了一种更优雅的方法来解决这个问题:iOS扩展——致命异常:com.firebase。core Default app已经配置好

    // Configure Firebase
    // ------------------
    if FIRApp.defaultApp() == nil {
        FIRApp.configure()            
    }

No more static this way ;)

不再以这种方式静态;)

#2


12  

I wrote FIRApp.configure() twice, that seemed to fix the error.

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

#3


3  

You can call once in AppDelegate init method to configure.

可以在AppDelegate init方法中调用一次来配置。

override init() {
   // Firebase Init
   FIRApp.configure()
}

#4


2  

just in case someone else stumble upon this problem. when use firebase sdk with googleSignIn sdk. you only have to configure them once. either do [[GGLContext sharedInstance] configureWithError: &configureError]; or [FIRApp configure]

以防万一有人发现这个问题。使用firebase sdk时使用googleSignIn sdk。您只需配置它们一次。或者是[[GGLContext sharedInstance]配置错误:&配置错误];或(FIRApp配置)

#5


0  

Class Name: AppDelegate+FCMPlugin.m

类名:AppDelegate + FCMPlugin.m

[FIRApp.configure()];

[FIRApp.configure());

Put this at the top most of this method

把这个放在这个方法的最上面

  • (BOOL)application:(UIApplication *)application customDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  • UIApplication(BOOL)应用程序:(*)应用customDidFinishLaunchingWithOptions:launchOptions(NSDictionary *)

#6


0  

For Swift 4

斯威夫特4

Had the same problem with crashing. When trying to reference from Firebase with a .plist file.

也有同样的问题。当试图从Firebase中引用.plist文件时。

(This fixed my problem.)

(这固定我的问题。)

Try writing this outside of or within the viewDidLoad method:

尝试在viewDidLoad方法之外或内部编写这个:

1. var ref: DatabaseReference!

Then reference it within the viewDidLoad method:

然后在viewDidLoad方法中引用:

2. Database.database().reference()

And now it's:

现在是:

FirebaseApp.configure()

Instead.

代替。

#1


32  

I had a problem with a Messages Extension :

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

If you're in an App Extension, you have no delegate, and you'll have to put the FIRApp.configure() in the init of your main ViewController (or in the viewDidLoad as suggested).

如果你在一个应用程序扩展中,你没有委托,你必须把FIRApp.configure()放在主视图控制器的init中(或者像建议的那样放在viewDidLoad中)。

Problem is : in a Messages Extension, if the user presses several messages in the thread opening your extension, init (or viewdidLoad) will be called several times, therefore crashing due to FIRApp.configure() called several times...

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

The solution I found was to create a static bool in the main View Controller :

我找到的解决方案是在主视图控制器中创建一个静态bool:

    static var isAlreadyLaunchedOnce = false // Used to avoid 2 FIRApp configure

and I test it before calling FIRApp.configure() in the init or viewDidLoad :

在调用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
    }

This way, no more crashes.

这样,就不会再发生撞车事故了。


Oh, I found a much more elegant way to solve the problem here : iOS Extension - Fatal Exception: com.firebase.core Default app has already been configured

我找到了一种更优雅的方法来解决这个问题:iOS扩展——致命异常:com.firebase。core Default app已经配置好

    // Configure Firebase
    // ------------------
    if FIRApp.defaultApp() == nil {
        FIRApp.configure()            
    }

No more static this way ;)

不再以这种方式静态;)

#2


12  

I wrote FIRApp.configure() twice, that seemed to fix the error.

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

#3


3  

You can call once in AppDelegate init method to configure.

可以在AppDelegate init方法中调用一次来配置。

override init() {
   // Firebase Init
   FIRApp.configure()
}

#4


2  

just in case someone else stumble upon this problem. when use firebase sdk with googleSignIn sdk. you only have to configure them once. either do [[GGLContext sharedInstance] configureWithError: &configureError]; or [FIRApp configure]

以防万一有人发现这个问题。使用firebase sdk时使用googleSignIn sdk。您只需配置它们一次。或者是[[GGLContext sharedInstance]配置错误:&配置错误];或(FIRApp配置)

#5


0  

Class Name: AppDelegate+FCMPlugin.m

类名:AppDelegate + FCMPlugin.m

[FIRApp.configure()];

[FIRApp.configure());

Put this at the top most of this method

把这个放在这个方法的最上面

  • (BOOL)application:(UIApplication *)application customDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  • UIApplication(BOOL)应用程序:(*)应用customDidFinishLaunchingWithOptions:launchOptions(NSDictionary *)

#6


0  

For Swift 4

斯威夫特4

Had the same problem with crashing. When trying to reference from Firebase with a .plist file.

也有同样的问题。当试图从Firebase中引用.plist文件时。

(This fixed my problem.)

(这固定我的问题。)

Try writing this outside of or within the viewDidLoad method:

尝试在viewDidLoad方法之外或内部编写这个:

1. var ref: DatabaseReference!

Then reference it within the viewDidLoad method:

然后在viewDidLoad方法中引用:

2. Database.database().reference()

And now it's:

现在是:

FirebaseApp.configure()

Instead.

代替。