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

标签 ios swift firebase swift3 firebase-authentication

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

我尝试将我的应用同步到 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/

相关文章:

ios - 重新加载 uitableviewcell 时随机滚动,iOs/Swift

ios - 为 preferredFontForTextStyle 自定义 UIFont

ios - fatal error : unexpectedly found nil while unwrapping an Optional value (lldb)

swift - 从右向左连续,无需推送或呈现 ViewController

android - 防止 firestore 中出现重复条目

iOS 背景音频流 (m3u) 在设备上不起作用(但在模拟器中起作用)

xcode - 在 Swift 的 NSScrollView 和 NSTextView 中显示控制台输出

ios - UIPasteboard 没有提供选项,如果有多个字符串则粘贴什么

javascript - 带有 firebase 的 Google Polymer : timing

android - Firebase,相同方法中的第二个 push() 不起作用