Firebase - 检查用户名是否失败

时间:2016-12-08 19:56:16

标签: ios swift firebase swift3 firebase-realtime-database

我正在尝试检查在我的应用中输入的用户名是否与我的Firebase数据库中的任何用户名相匹配,如果是,请显示标签并禁用继续segue /按钮。

相反,我得到一个常数错误:

  signal SIGABRT (lldb) // for app delegate

这是我的代码:     @IBAction func checkUsernameEntered(_ sender:UITextField){

    let ref = FIRDatabase.database().reference(fromURL: "DATABASE_URL")

    ref.child("users")

        .queryOrdered(byChild: "kid/username")

        .queryEqual(toValue: chooseUsernameTextField.text)

        .observeSingleEvent(of: .value, with: { snapshot in
            if !snapshot.exists(){

                print("The username entered has not been previously registered. Tap 'Next' to proceed.")
                self.bottomNextButtonThree.isEnabled = true
                UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseOut, animations: { self.uhOhWarningLabel.alpha = 0 }, completion: nil)

            }

            else

            {

                print("The entered username has been previously registered. Re-enter to proceed.")
                self.bottomNextButtonThree.isEnabled = false
                UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseOut, animations: { self.uhOhWarningLabel.alpha = 1.0 }, completion: nil)
            }

        })

这是我在firebase上的数据库结构

image of database structure

感谢任何帮助

1 个答案:

答案 0 :(得分:0)

这就是问题所在

let ref = FIRDatabase.database().reference(fromURL: "DATABASE_URL")

所以这样做(只是一个粗略的例子)

class ViewController: UIViewController {

    var ref: FIRDatabaseReference!

    override func viewDidLoad() {
        super.viewDidLoad()
        ref = FIRDatabase.database().reference()

        ref.child("test_key").setValue("test_value")
    }
}

Firebase知道它的应用路径,因为它在DATABASE_URL条目的GoogleService-Info.plist中定义。

Firebase网站在您在控制台中创建新应用时创建的文件。