gpt4 book ai didi

ios - firebase errorCodes 不会显示

转载 作者:行者123 更新时间:2023-11-28 05:46:09 27 4
gpt4 key购买 nike

我尝试为登录设置错误代码,例如用户想要输入他的个人资料但输入了错误的密码,他会收到他输入错误密码的通知......但如果我尝试这样做只是在没有登录的情况下将我带到了正常的提要页面,所以 errorCode 甚至都没有出现...

    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 以来发生了一些变化,但我没有发现任何相关内容

最佳答案

<强>1。正确获取错误码

为了正确获取错误代码,您需要将 Swift Error 转换为 NSError

您可以使用以下代码:

if error != nil {
let ns_error = error! as NSError
print(ns_error.code)
}

<强>2。在主线程的完成 block 上执行 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)
}

关于ios - firebase errorCodes 不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54702945/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com