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

时间:2017-02-12 20:38:47

标签: ios swift firebase swift3 firebase-authentication

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

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

  

尚未配置默认的Firebase应用。将[FIRApp configure]添加到应用程序初始化

App 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" )

                }
            }

        }
    }

}

1 个答案:

答案 0 :(得分:0)

在您实际尝试访问数据库之前,似乎没有执行对 FIRApp.configure()的调用。而不是在

中进行配置
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> ObjCBool { 

尝试覆盖init方法并在其中cconfigure 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