Ios 使用Firebase Auth时应用程序崩溃,原因:';已配置默认应用程序;
我正在构建我的第一个iOS应用程序,我正在使用Firebase处理身份验证、数据库等。我添加了一个注册屏幕,并使用以下代码创建了一个新用户:Ios 使用Firebase Auth时应用程序崩溃,原因:';已配置默认应用程序;,ios,swift,firebase,firebase-authentication,Ios,Swift,Firebase,Firebase Authentication,我正在构建我的第一个iOS应用程序,我正在使用Firebase处理身份验证、数据库等。我添加了一个注册屏幕,并使用以下代码创建了一个新用户: FIRAuth.auth()?.createUserWithEmail(emailAddress.text!, password: password.text!, completion: { (user, error) in }) 当用户点击注册按钮时,会出现一个序列,该序列会将他们带回原始登录视图控制器。然而,当我运行应用程序时,它挂
FIRAuth.auth()?.createUserWithEmail(emailAddress.text!, password: password.text!, completion: { (user, error) in
})
当用户点击注册按钮时,会出现一个序列,该序列会将他们带回原始登录视图控制器。然而,当我运行应用程序时,它挂在启动屏幕上。以下是调试器输出:
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)
2016-06-19 14:35:05.402 unitaskr[4386:82981]配置默认应用程序。
2016-06-19 14:35:05.413 unitaskr[4386:]Firebase Analytics v.3200000启动
2016-06-19 14:35:05.414 unitaskr[4386:]要启用调试日志记录,请设置以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅…)
2016-06-19 14:35:05.419:FIRInstanceID AppDelegate代理已启用,将swizzle应用程序代理远程通知处理程序。要禁用,请将“FirebaseAppDelegateProxyEnabled”添加到您的Info.plist并将其设置为否
2016-06-19 14:35:05.418 unitaskr[4386:]已成功自动创建Firebase Analytics应用程序代理。要禁用代理,请在Info.plist中将标志FirebaseAppDelegateProxyEnabled设置为NO
2016-06-19 14:35:05.430 unitaskr[4386:82981]***由于未捕获的异常“com.firebase.core”而终止应用程序,原因是:“已配置默认应用程序。”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x00000001100a8d85例外预处理+165
1 libobjc.A.dylib 0x00000001108e7deb objc_异常_抛出+48
2 CoreFoundation 0x00000001100a8cbd+[N异常提升:格式:][205
3 unitaskr 0x000000010b58844d+[FIRApp配置DefaultAppWithOptions:sendingNotifications:][102
4 unitaskr 0x000000010b588238+[FIRApp配置]+302
5 unitaskr 0x000000010B541A\u TFC8 UNITASKR11应用程序FTCSO13UI2应用程序已使用选项GSQGVS10字典YSO8NSObjectPS9任何对象\uuuuuuuuuuuuuuuu Sb+266完成启动
6 unitaskr 0x000000010B54204 \u TTOFC8 UNITASKR11应用程序FTCSO13 UI2应用程序已使用选项GSQGVS10字典YCSO8 NSObjectPS9任何对象\uuuuuuuuuuu Sb+180完成启动
7 UIKit 0x000000010e5bf9ac-[UIApplication\u处理的远程回调,带选项:isSuspended:restoreState:+272
8 UIKit 0x000000010e5c0c0d-[UIApplication\u callInitializationDelegatesForMainScene:transitionContext:+3415
9 UIKit 0x000000010e5c7568-[UIApplication\u在主场景中运行:transitionContext:completion:+1769
10 UIKit 0x000000010e5c4714-[UIApplication WorkspaceDiEndTransaction:][188
11 FrontBoardServices 0x00000001127b78c8 \uuu FBSSERIALQUEUE \uu正在呼叫\uu OUT \uu到\uu块\uuuu+24
12 FrontBoardServices 0x00000001127b7741-[FBSSerialQueue\u performNext]+178
13 FrontBoardServices 0x00000001127b7aca-[FBSSerialQueue\u performNextFromRunLoopSource]+45
14 CoreFoundation 0x000000010ffce301\uuuu CFRUNLOOP\u正在调用\u OUT\u以执行\u函数\uuu+17
15 CoreFoundation 0x000000010ffc422c\uuu CFRunLoopDoSources0+556
16 CoreFoundation 0x000000010ffc36e3_u CFRunLoopRun+867
17 CoreFoundation 0x000000010ffc30f8 CFRunLoopRunSpecific+488
18 UIKit 0x000000010e5c3f21-[UIApplication_run]+402
19 UIKit 0x000000010e5c8f09 UIApplicationMain+171
20 unitaskr 0x000000010b542a42干管+114
21 libdyld.dylib 0x00000001113b692d开始+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)
我可以根据需要提供更多信息,如有任何帮助/建议,我将不胜感激,因为我刚刚起步,希望尽可能多地学习。祝你今天愉快 我写了两次
FIRApp.configure()
,似乎修复了错误。您可以在AppDelegate init方法中调用一次进行配置
override init() {
// Firebase Init
FIRApp.configure()
}
以防其他人偶然发现这个问题。 将
firebase
sdk与googlesign
sdk一起使用时。您只需配置它们一次。或者
[[GlgContext sharedInstance]配置错误:&configureError];
或
[FIRApp配置]
我的消息扩展出现问题:
如果您使用的是应用程序扩展名,则没有委托,您必须将FIRApp.configure()放在主ViewController的init中(或按建议放在viewDidLoad中)
问题是:在消息扩展中,如果用户在打开扩展的线程中按下多条消息,init(或viewdidLoad)将被多次调用,因此由于多次调用FIRApp.configure(),导致崩溃
我找到的解决方案是在主视图控制器中创建一个静态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
}
这样,就不会再发生碰撞
哦,我在这里找到了一个更优雅的方法来解决这个问题:
这样就不再有静电;) 类名:AppDelegate+FCMPlugin.m [FIRApp.configure()]强> 把这个放在这个方法的最上面
- (BOOL)application:(UIApplication *)application customDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(![FIRApp defaultApp]){
[FIRApp configure];}}
适用于Swift 4 和撞车有同样的问题。尝试使用.plist文件从Firebase引用时 (这解决了我的问题。) 尝试在viewDidLoad方法外部或内部编写此命令:
1. var ref: DatabaseReference!
2. Database.database().reference()
然后在viewDidLoad方法中引用它:
1. var ref: DatabaseReference!
2. Database.database().reference()
现在是:
FirebaseApp.configure()
相反。这是关于这个问题的另一个解决方案。 1/签入“AppDelegate.swift”,我们将看到如下内容
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
2/删除“FirebaseApp”。
override init() {
FirebaseApp.configure()
}
if FirebaseApp.app() == nil {
FirebaseApp.configure()
}
if FirebaseApp.app() == nil {
/// code snippet
}
if #available(iOS 13.0, *) {
} else {
FirebaseApp.configure()
}
if #available(iOS 13.0, *) {
FirebaseApp.configure()
}
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)
}
}
if #available(iOS 13.0, *) {
} else {
FirebaseApp.configure()
}