ios - Firebase 登录错误消息未显示

标签 ios swift firebase uialertcontroller

当用户使用正确的凭据登录时,SVProgressHUD 会正确显示和关闭,并且用户会正确转到主屏幕。但是,当密码或电子邮件不正确时,SVProgressHUD 会不断显示并且不会弹出任何警报。

@IBAction func signInButton(_ sender: Any) {

    self.view.endEditing(true)
    let email = emailText.text!.lowercased()
    let finalEmail = email.trimmingCharacters(in: .whitespacesAndNewlines)
    let password = passwordText.text!

    if finalEmail.isEmpty || password.isEmpty {

        let alertController = UIAlertController(title: "Error!", message: "Please fill in all the fields.", preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
        present(alertController, animated: true, completion: nil)

    }else {
      SVProgressHUD.show()

        Auth.auth().signIn(withEmail: email, password: password) { (user, error) in

            if error == nil {
                if let user = user {
                    print("\(user.displayName!) has been signed in")

                   SVProgressHUD.dismiss()

        //            self.enter()
             self.performSegue(withIdentifier: "signInHome", sender: nil)

                }else{
                     SVProgressHUD.dismiss()
                   print("error")
                    let alertController = UIAlertController(title: "Low Blow!", message: "incorrect credentials", preferredStyle: .alert)
                    alertController.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
                    self.present(alertController, animated: true, completion: nil)


                    print(error?.localizedDescription as Any)
                }
            }
        }
    }

}

最佳答案

如果错误为 null,您忘记关闭 SVProgressHUD

检查这段代码

@IBAction func signInButton(_ sender: Any) 
{

    self.view.endEditing(true)
    let email = emailText.text!.lowercased()
    let finalEmail = email.trimmingCharacters(in: .whitespacesAndNewlines)
    let password = passwordText.text!

    if finalEmail.isEmpty || password.isEmpty 
    {

        let alertController = UIAlertController(title: "Error!", message: "Please fill in all the fields.", preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
        present(alertController, animated: true, completion: nil)

    }
    else 
    {
        SVProgressHUD.show()

        Auth.auth().signIn(withEmail: email, password: password) 
        { 
            (user, error) in

            if error == nil 
            {
                if let user = user 
                {
                    print("\(user.displayName!) has been signed in")
                    SVProgressHUD.dismiss()
                    self.performSegue(withIdentifier: "signInHome", sender: nil)
                }
                else
                {
                    SVProgressHUD.dismiss()
                    print("error")
                    let alertController = UIAlertController(title: "Low Blow!", message: "incorrect credentials", preferredStyle: .alert)
                    alertController.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
                    self.present(alertController, animated: true, completion: nil)
                    print(error?.localizedDescription as Any)
                }
            }
            else 
            {
                SVProgressHUD.dismiss()
            }
        }
    }
}

关于ios - Firebase 登录错误消息未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48483580/

相关文章:

ios - 如何实现AAShareBubles

ios - 如何打印NSSet的内容?

swift - Pickerview 选择行和 didSelectRowAt 函数

firebase - Firestore 查询比较没有数组包含的两个数组

java - 从 console.firebase.google.com 取消用户后,用户身份验证仍然存在

php - 如何从 IOS 模拟器访问我的服务器 MySql 以快速检索数据

ios - 有没有办法为 native IOS 应用程序创建可用的滚动条?

ios - 如何设置添加了导航 Controller 的 TableView 的背景图像 - Swift 1.2

ios - 推送客户端错误 : Invalid Signature

authentication - React/Rebase/Firebase 警告 : Permission Denied - How do I add user authentication?