gpt4 book ai didi

ios - 将 [FIRApp configure] 添加到您的应用程序初始化错误中

转载 作者:行者123 更新时间:2023-11-30 12:41:21 25 4
gpt4 key购买 nike

我是编码新手,所以如果答案很明显,我很抱歉。

我尝试将我的应用同步到 Firebase 服务器,安装了 cocoapods,添加了 GoogleService 信息 plist。但是,当我尝试创建新用户时,出现错误:

The default Firebase app has not yet been configured. Add [FIRApp configure] to your application initialization

应用程序委托(delegate)

import UIKit
import Firebase


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> ObjCBool {

FIRApp.configure()

return true
}

我用来注册用户的代码

import UIKit
import Firebase
import FirebaseAuth

class signUpViewController: UIViewController {



@IBOutlet var fullNameTextField: UITextField?
@IBOutlet var contactNumberTextField: UITextField?
@IBOutlet var emailTextField: UITextField?
@IBOutlet var passwordTextField: UITextField?
@IBOutlet var dateOfBirth: UIDatePicker?


func createMyAlert(title: String, message: String) {

let alarm = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alarm.addAction(UIAlertAction(title: "ok", style: .default, handler: { (ACTION) -> Void
in self.dismiss(animated: true, completion: nil)

}))

self.present(alarm, animated: true, completion: nil)
}

@IBAction func continueButtonPressed(_ sender: Any) {

if fullNameTextField?.text == "" || contactNumberTextField?.text == "" || emailTextField?.text == "" || passwordTextField?.text == "" {

createMyAlert(title: "Error", message: "Please complete all fieds")

} else {

// This will create a new user
FIRAuth.auth()?.createUser(withEmail: (self.emailTextField?.text!)!, password: (self.passwordTextField?.text!)!) { (user, error) in


// this code will check the user isnt nil

if let u = user {

self.performSegue(withIdentifier: "createProfile", sender: self)

}
else
{

self.createMyAlert(title: "Oops", message: "Error" )

}
}

}
}

}

最佳答案

看起来在您实际尝试访问数据库之前,对 FIRApp.configure() 的调用并未被执行。而不是配置

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> ObjCBool { 

尝试重写 init 方法并在 tha 中配置 fireapp,如下所示:

override init() {
super.init()
FIRApp.configure()
// not really needed unless you really need it FIRDatabase.database().persistenceEnabled = true
}

查看以下链接了解更多详细信息:

The default app has not been configured yet

关于ios - 将 [FIRApp configure] 添加到您的应用程序初始化错误中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42192961/

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