我正在构建我的第一个iOS应用程序,我正在使用Firebase来处理身份验证,数据库等。我添加了一个注册屏幕并使用以下代码创建了一个新用户:
FIRAuth.auth()?.createUserWithEmail(emailAddress.text!, password: password.text!, completion: { (user, error) in
})
当用户点击注册按钮时,会有一个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)
我可以根据需要提供更多信息,我将非常感谢任何帮助/建议,因为我刚刚开始并希望尽可能多地学习。祝你有美好的一天!
答案 0 :(得分:43)
我遇到了讯息分机:
的问题如果您在 App Extension 中,则没有委托,您必须将FIRApp.configure()放在主ViewController的init中(或者在viewDidLoad中)所建议的)。
问题是:在消息扩展中,如果用户在打开扩展的线程中按下几条消息,init(或viewdidLoad)将被多次调用,因此多次调用FIRApp.configure()导致崩溃...
我找到的解决方案是在主视图控制器中创建一个静态bool:
z
我在init或viewDidLoad中调用FIRApp.configure()之前测试它:
static var isAlreadyLaunchedOnce = false // Used to avoid 2 FIRApp configure
这样,不再崩溃。
哦,我找到了一个更优雅的方法来解决这个问题: iOS Extension - Fatal Exception: com.firebase.core Default app has already been configured
// 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
}
这样不再是静态的;)
答案 1 :(得分:20)
我写了FIRApp.configure()
两次,这似乎解决了错误。
答案 2 :(得分:8)
这是有关此问题的其他解决方案。 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.configure()”
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
3 /将以下代码添加到“ AppDelegate.swift”中
override init() {
FirebaseApp.configure()
}
4 /转到“ ViewController.swift”并添加代码
if FirebaseApp.app() == nil {
FirebaseApp.configure()
}
5 /再次构建并运行它就可以了。谢谢!
答案 3 :(得分:6)
您可以在AppDelegate init方法中调用一次进行配置。
override init() {
// Firebase Init
FIRApp.configure()
}
答案 4 :(得分:6)
班级名称:AppDelegate + FCMPlugin.m
<强> [FIRApp.configure()]; 强>
将此放在此方法的最顶层
- (BOOL)application:(UIApplication *)application customDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(![FIRApp defaultApp]){
[FIRApp configure];}}
答案 5 :(得分:3)
以防其他人偶然发现这个问题。
使用firebase
sdk与googleSignIn
sdk时的情况。你只需要配置一次。或者
[[GGLContext sharedInstance] configureWithError: &configureError];
要么
[FIRApp configure]
答案 6 :(得分:2)
对于Swift 4,
if FirebaseApp.app() == nil {
/// code snippet
}
答案 7 :(得分:1)
如果您使用的是Scene代理,并且具有更多的iOS版本(例如9、10到13),则必须以这种方式调用 AppDelegate.swift :< / p>
if #available(iOS 13.0, *) {
} else {
FirebaseApp.configure()
}
并在 SceneDelegate.swift 中以这种方式:
if #available(iOS 13.0, *) {
FirebaseApp.configure()
}
这些设置将排除以下错误: *
***由于未捕获的异常'com.firebase.core'而终止应用程序,原因:'已经配置了默认应用程序。'
答案 8 :(得分:1)
这是我的 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)
}
}
您可以删除此 FirebaseApp.configure()
或添加
if #available(iOS 13.0, *) {
} else {
FirebaseApp.configure()
}
两者都为我工作
答案 9 :(得分:0)
适用于Swift 4
崩溃时遇到同样的问题。尝试使用.plist文件从Firebase引用时。
(这解决了我的问题。)
尝试在viewDidLoad方法之外或之内编写:
1. var ref: DatabaseReference!
然后在viewDidLoad方法中引用它:
2. Database.database().reference()
现在是:
FirebaseApp.configure()
相反。
答案 10 :(得分:0)
这是因为您已经在 AppDelegate 中初始化了 FirebaseApp.configure()。 请确保它只配置一次,错误应该消失。