使用Firebase身份验证时应用程序崩溃,原因:“默认应用程序已被配置。 [英] App crashing when using Firebase Auth, reason: 'Default app has already been configured.'

查看:3059
本文介绍了使用Firebase身份验证时应用程序崩溃,原因:“默认应用程序已被配置。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

})

当用户点击注册按钮时,应该把他们带回原来的登录视图控制器。但是,当我运行应用程序,它挂在启动屏幕上。这里是调试器输出:

  2016-06-19 14:35:05.402 unitaskr [4386:82981]配置默认的应用程序。 
2016-06-19 14:35:05.413 unitaskr [4386:]< FIRAnalytics / INFO> Firebase Analytics v.3200000开始
2016-06-19 14:35:05.414 unitaskr [4386:]< FIRAnalytics / INFO>要启用调试日志记录,请设置以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅...)
2016-06-19 14:35:05.419:< FIRInstanceID / WARNING> FIRInstanceID启用了AppDelegate代理,将swizzle应用程序委托给远程通知处理程序。要禁用将FirebaseAppDelegateProxyEnabled添加到Info.plist并将其设置为NO
2016-06-19 14:35:05.418 unitaskr [4386:]< FIRAnalytics / INFO>成功自动创建Firebase Analytics应用程序委托代理。要禁用代理,请在Info.plist
2016-06-19 14:35:05.430 unitaskr [4386:82981]中设置标志FirebaseAppDelegateProxyEnabled为NO。由于未捕获的异常com.firebase,终止应用程序。核心',原因:'默认的应用程序已被配置'
***第一个抛出调用堆栈:

0 CoreFoundation 0x00000001100a8d85 __exceptionPreprocess + 165
1 libobjc.A。 dllib 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 _TFC8unitaskr11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryCSo8NSObject Ps9AnyObject____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:以NSException类型的未捕获异常终止
(lldb)

我可以额外提供根据需要形成,任何帮助/建议将不胜感激,因为我刚刚开始,并希望尽可能地学习。祝你有美好的一天!

我在使用讯息附加信息时遇到问题:

如果您在应用程序扩展中,则没有委托,您必须将FIRApp.configure()放在主ViewController的init中问题是:在Message Extension中,如果用户在打开你的扩展的线程中按下几条消息,init(或viewdidLoad)将被调用几次,因此FIRApp.configure()调用几次崩溃...

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

  static var isAlreadyLaunchedOnce = false //用于避免2 FIRApp配置


 

//配置Firebase
// ------------------
//我们检查i f FIRApp已经配置了静态变量,否则会崩溃...
if!MessagesViewController.isAlreadyLaunchedOnce {
FIRApp.configure()

MessagesViewController.isAlreadyLaunchedOnce = true



$ b $ p
$ b

这样,就不会再崩溃了。 b $ b




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

  //配置Firebase 
// ----------------- -
FIRApp.defaultApp()== nil {
FIRApp.configure()
}

这种方式没有更多的静态;)

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:

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:

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!

解决方案

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

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

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

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

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

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

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

No more static this way ;)

这篇关于使用Firebase身份验证时应用程序崩溃,原因:“默认应用程序已被配置。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆