预先形成segue时的firebase分析错误

时间:2017-05-06 21:21:02

标签: ios firebase firebase-realtime-database firebase-authentication firebase-analytics

当我执行segue时,应用程序崩溃了。我检查了是否有任何sigbrt错误,但没有。我认为这是日志中的firebase分析。此错误来自日志:

  

以NSException类型的未捕获异常终止。

代码

@IBOutlet weak var email: UITextField! 
@IBOutlet weak var password: UITextField!
@IBOutlet weak var adduser: UIButton!
@IBOutlet weak var errormessege: UILabel!

var databaseref = FIRDatabase.database().reference()


override func viewDidLoad() {
    super.viewDidLoad()

    password.isSecureTextEntry = true
    adduser.isEnabled = false

}

@IBAction func didtapcancel(_ sender: Any) {
    dismiss(animated: true, completion: nil)
}






@IBAction func didtapadd(_ sender: Any) {
    adduser.isEnabled = false

   FIRAuth.auth()?.createUser(withEmail: email.text!, password: password.text!, completion: {(user,error) in

        if error != nil {

            if error!._code == 17999 {
                       self.errormessege.text =  "Invalid email address"   }
            else {

              self.errormessege.text =  error?.localizedDescription
            }
        }

        else
        {


           FIRAuth.auth()?.signIn(withEmail: self.email.text!, password: self.password.text!, completion: {(user,error) in

                if (error == nil) {


                    self.databaseref.child("users").child(user!.uid).child("email").setValue(self.email.text!)

                    self.performSegue(withIdentifier: "hi", sender: nil)



                }
                else {
                    self.errormessege.text =  error?.localizedDescription

                }
            })
        }


    }
    )


     }



@IBAction func didtextchange(_ sender: Any) {

        if((email.text?.characters.count)!>0){
        adduser.isEnabled = true}
    else{
        adduser.isEnabled = false}

}
    @IBAction func did4(_ sender: Any) {
    if((password.text?.characters.count)!>0){
        adduser.isEnabled = true}
    else{
        adduser.isEnabled = false}
}

1 个答案:

答案 0 :(得分:0)

如果没有更多代码和整个场景摆在我面前,很难明确指出代码和Firebase之间发生的事情。有助于您追踪此错误的一件事是验证您从@IBOutlets每个步骤中抽出的数据。这样你的程序就不会强行解开这些对象,而是让你的代码暴露出风险。

@IBOutlet weak var email: UITextField! 
@IBOutlet weak var password: UITextField!
@IBOutlet weak var adduser: UIButton!
@IBOutlet weak var errormessege: UILabel!

var databaseref = FIRDatabase.database().reference()

override func viewDidLoad() {
    super.viewDidLoad()
    password.isSecureTextEntry = true
    adduser.isEnabled = false
}

@IBAction func didtapcancel(_ sender: Any) {
    dismiss(animated: true, completion: nil)
}

@IBAction func didtapadd(_ sender: Any) {
    adduser.isEnabled = false

    guard let emailText = email.text,
       let passwordText = password.text else {
       // Handle error safely
       print("Error unrapping email text or password text")
       return
    }

    FIRAuth.auth()?.createUser(withEmail: emailText, password: passwordText, completion: { (user,error) in

        if error != nil {
            if error!._code == 17999 {
              self.errormessege.text =  "Invalid email address"   
            } else {
              self.errormessege.text =  error?.localizedDescription
            }
        } else {
            FIRAuth.auth()?.signIn(withEmail: emailText, password: passwordText, completion: { (user, error) in

                if (error == nil) {
                    guard let uid = user.uid else {
                        // handle error safely
                        print("Error with user uid")
                        return
                    }
     self.databaseref.child("users").child(uid).child("email").setValue(emailText)
                    self.performSegue(withIdentifier: "hi", sender: nil)
                }
                else {
                    self.errormessege.text =  error?.localizedDescription

                }
            })
        }
    })
}

@IBAction func didtextchange(_ sender: Any) {

    guard let emailText = email.text else {
        // Return error safely
        print("Error unrapping email text")
        return
    }

    if emailText.characters.count> 0 {
        adduser.isEnabled = true
    } else{
        adduser.isEnabled = false
    }
}