gpt4 book ai didi

swift - 如何处理 Firebase Auth 错误?/Swift/Firebase

转载 作者:行者123 更新时间:2023-12-05 03:44:51 25 4
gpt4 key购买 nike

嘿伙计们,有人能告诉我如何处理这个吗?我尝试了很多,但如果我纠正一个错误,另一个错误就会出现......提前致谢

Auth.auth().createUser(withEmail: eMailTextField.text!, password: passwordTextField.text!) { (data, error) in
if error != nil {
if let errCode = error as NSError? {

guard let errorCode = AuthErrorCode(rawValue: error) else {
print("there was an error logging in but it could not be matched with a firebase code")
return

}

switch errorCode {
case .FIRAuthErrorCodeNetworkError:
print("No Internet Connection")
case .ErrorCodeEmailAlreadyInUse:
print("in use")
default:
print("Create User Error: \(error!)")
}

}

} else {
print("all good... continue")
}

最佳答案

您可以连接到 NSError,然后根据 error.code 创建 AuthErrorCode:

Auth.auth().createUser(withEmail: "MyEmail", password: "MyPassword") { authResult, error in
if error != nil, let error = error as NSError? {
if let errorCode = AuthErrorCode(rawValue: error.code) {
switch errorCode {
case .invalidEmail:
break
case .emailAlreadyInUse:
break
default:
break
}
}
} else {
//no error
}
}

请注意,我只列出了几个 errorCode 可能性 - 它们的列表非常广泛。

关于swift - 如何处理 Firebase Auth 错误?/Swift/Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66197424/

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