gpt4 book ai didi

ios - 使用 Firebase Auth 时应用崩溃,原因 : 'Default app has already been configured.'

转载 作者:IT王子 更新时间:2023-10-29 05:03:33 26 4
gpt4 key购买 nike

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

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

})

当用户点击注册按钮时,会有一个 segue 将他们带回原始登录 View Controller 。但是,当我开始运行该应用程序时,它卡在启动屏幕上。这是调试器输出:

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)

我可以根据需要提供其他信息,任何帮助/建议都将不胜感激,因为我刚刚起步并希望尽可能多地学习。祝你有美好的一天!

最佳答案

我在使用消息扩展 时遇到了问题:

如果您在App Extension 中,您没有委托(delegate),您必须将 FIRApp.configure() 放在主 ViewController 的初始化中(或在 viewDidLoad 中作为建议)。

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

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

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

我在 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
}

这样,就不会再发生崩溃了。


哦,我在这里找到了一个更优雅的方法来解决这个问题: iOS Extension - Fatal Exception: com.firebase.core Default app has already been configured

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

这样就不再是静态的 ;)

关于ios - 使用 Firebase Auth 时应用崩溃,原因 : 'Default app has already been configured.' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37910766/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com