繁体   English   中英

使用Firebase创建新用户后未执行Segue -Swift

[英]Segue after new user creation using firebase not being performed -Swift

但是我遇到了两个问题,因为我在执行每个问题时都使用了相同的逻辑,所以我将继续将所有问题简化为一个问题。 基本上,我尝试在使用firebase执行createUser函数之后执行初始化,然后执行Firebase处理的login功能后,但是,当单击SignUpLogin按钮时,似乎没有响应。 以下是每个@IBActions的代码

 @IBAction func signUpComplete(_ sender: Any) {
    FIRAuth.auth()?.createUser(withEmail: signUpEmailField.text!, password: signUpPasswordField.text!, completion: { (user: FIRUser?, error) in
        if self.signUpEmailField.text == "" || self.signUpPasswordField.text == "" {
                let alert = UIAlertController(title: "Oops!", message: "A valid E-mail and Password are Required", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
                    self.present(alert, animated: true, completion: nil)



        if FIRAuthErrorCode.errorCodeEmailAlreadyInUse != nil {

            let emailExists = UIAlertController(title: "Oops!", message: "A user with this E-Mail already exists!", preferredStyle: UIAlertControllerStyle.alert)
            emailExists.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
            self.present(emailExists, animated: true, completion: nil)


            }

        else {

            DispatchQueue.main.async () {
                self.performSegue(withIdentifier: "signUpSucceededSegue", sender: self)
            }
            }

            }
        })
}

@IBAction func loginButton(_ sender: Any) {

    FIRAuth.auth()?.signIn(withEmail: emailLoginField.text!, password: passwordLoginField.text!, completion: { (user: FIRUser?, error) in
            if self.emailLoginField.text == "" || self.passwordLoginField.text == ""{

                let alert = UIAlertController(title: "Alert", message: "E-Mail is Required", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
                self.present(alert, animated: true, completion: nil)

            if FIRAuthErrorCode.errorCodeUserNotFound != nil {

                let invalidLogin = UIAlertController(title: "Alert", message: "E-Mail/Password Incorrect", preferredStyle: UIAlertControllerStyle.alert)
                invalidLogin.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
                self.present(invalidLogin, animated: true, completion: nil)

            }

        else{


                DispatchQueue.main.async () {

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

                }

            }


        }
    })

乍看之下是否存在明显的逻辑错误,还是有更好的方法来实现这些功能的安全?

  • 将导航控制器嵌入到故事板的第一个视图
  • 然后尝试使用此代码:-

     @IBAction func signUpComplete(_ sender: Any) { if self.signUpEmailField.text == "" || self.signUpPasswordField.text == "" { let alert = UIAlertController(title: "Oops!", message: "A valid E-mail and Password are Required", preferredStyle: UIAlertControllerStyle.alert) alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) self.present(alert, animated: true, completion: nil) }else{ FIRAuth.auth()?.createUser(withEmail: self.signUpEmailField!.text, password: self.signUpPasswordField!.text, completion: { (user, err) in if let ErrorCode = FIRAuthErrorCode(rawValue: err!._code){ switch ErrorCode { case .errorCodeEmailAlreadyInUse : let emailExists = UIAlertController(title: "Oops!", message: "A user with this E-Mail already exists!", preferredStyle: UIAlertControllerStyle.alert) emailExists.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) self.present(emailExists, animated: true, completion: nil) break default : break } }else{ let nextView = self.navigationController!.storyboard!.instantiateViewController(withIdentifier: "signUpSucceededSegue") self.navigationController!.pushViewController(nextView, animated: true) } }) } } 

然后以类似的方式更改您的其他代码块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM