Ios firebase错误代码赢得';我没有出现
我尝试为登录设置错误代码,例如,一个用户想要输入他的个人资料,但输入了错误的密码,他会得到通知,他输入了错误的密码。。。但是如果我尝试它,它只会将我带到正常的提要页面,而没有登录,因此错误代码甚至不会显示Ios firebase错误代码赢得';我没有出现,ios,swift,firebase,firebase-authentication,Ios,Swift,Firebase,Firebase Authentication,我尝试为登录设置错误代码,例如,一个用户想要输入他的个人资料,但输入了错误的密码,他会得到通知,他输入了错误的密码。。。但是如果我尝试它,它只会将我带到正常的提要页面,而没有登录,因此错误代码甚至不会显示 Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in if error != nil { print(error ?? "
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
print(error ?? "")
if let errorCode = AuthErrorCode(rawValue: error!._code) {
switch errorCode {
case .invalidEmail:
print("invalid email")
let alertMessage = UIAlertController(title: "Email is invalid", message: "Use upper and lower characters along with numbers", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
alertMessage.dismiss(animated: true, completion: nil)
}))
self.present(alertMessage, animated: true, completion: nil)
case .accountExistsWithDifferentCredential:
print("wrong credential")
let alertMessage = UIAlertController(title: "Wrong Information", message: "The Account exists with different Credentials than entered from you", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
alertMessage.dismiss(animated: true, completion: nil)
}))
self.present(alertMessage, animated: true, completion: nil)
case .wrongPassword:
print("wrong password")
let alertMessage = UIAlertController(title: "Password is wrong", message: "Please enter the correct password for your account", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
alertMessage.dismiss(animated: true, completion: nil)
}))
self.present(alertMessage, animated: true, completion: nil)
default:
print("Other error!")
let alertMessage = UIAlertController(title: "Ouhhhh", message: "It seems like something went wrong. Please try again later.", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
alertMessage.dismiss(animated: true, completion: nil)
}))
self.present(alertMessage, animated: true, completion: nil)
}
}
return
} else {
//successfully logged in our user
self.messagesController?.fetchUserAndSetupNavBarTitle()
self.performSegue(withIdentifier: "showJobs", sender: nil)
SVProgressHUD.dismiss()
}})
有人能帮我吗?自firebase 5以来,似乎有一些变化,但我没有发现这方面的任何变化。正确获取错误代码 为了正确获取错误代码,您需要将Swifterror转换为NSError 您可以使用以下代码:
if error != nil {
let ns_error = error! as NSError
print(ns_error.code)
}
2。在主线程的完成块上执行与UI相关的任务
case .invalidEmail:
print("invalid email")
DispatchQueue.main.async {
// Update UI elements here
let alertMessage = UIAlertController(title: "Email is invalid", message: "Use upper and lower characters along with numbers", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
alertMessage.dismiss(animated: true, completion: nil)
}))
self.present(alertMessage, animated: true, completion: nil)
}
您需要在主线程中处理所有警报和与UI相关的情况
尝试在显示警报之前添加延迟
func delayExecution(seconds delay:Double, closure:@escaping ()->()) {
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure)
}
这里有印刷品吗<代码>打印(错误??)是的,但我没有得到警报,而是被呈现给第二个vcIt,这意味着它不会进入if状态。如果您打印
authorrorcode(rawValue:error.\u code)
您有什么吗?例如,如果它打印一个数组,这意味着您需要循环到数组中以找到一个值OK nice,谢谢,我现在明白我的问题是什么了,但遗憾的是,我得到的AlertController作为错误不在窗口层次结构中。。。我在viewDidLoad()中读到一些我需要调用警报的内容,但在我的情况下我应该如何做?您是否在viewDidLoad()中处理此登录逻辑?不,我在按下按钮时执行此操作。。。当我在viewDidLoad中调用该函数时,当视图出现时,我会立即收到所有警报尝试在显示警报之前添加1-3秒的延迟,以查看其是否有效。我已经用您可以使用的延迟函数更新了答案。添加了它,但没有更改:/Windows层次结构的错误与以前相同