问题描述
我无法理解如何在新版本的Firebase中读取FIRAuthErrorNameKey。以下是我到目前为止,但let errorCode = FIRAuthErrorNameKey行是不正确的。从阅读,我也尝试从userInfo访问错误代码,但没有成功,没有想法。
//向Firebase发送请求以添加用户以注册用户
FIRAuth .auth()?。createUserWithEmail(emailTextField.text !,密码:passwordTextField.text !,完成:{(user,error)in
//检查错误并相应地响应用户
if error!= nil {
let errorCode = FIRAuthErrorNameKey
switch errorCode {
caseFIRAuthErrorCodeEmailAlreadyInUse:
//相应地添加逻辑
case ...:
//相应地添加逻辑
案例默认值:
//相应地添加逻辑
code $ pre
解决方案试试这个。这对我有用。此外,粘贴到您的项目后。如果您需要查看所有 FIRAuthErrorCode
代码。将鼠标悬停在 .ErrorCodeInvalidEmail
上,然后按鼠标左键,它会显示其余的内容。
如果您有任何问题,请告诉我,并尽力帮助您。祝你好运!
FIRAuth.auth()?。createUserWithEmail(email,password:password){(user,error)in
if error!= nil {
if errCode = FIRAuthErrorCode(rawValue:error!._ code){
switch errCode {
case .ErrorCodeInvalidEmail:
print(invalid email)
case .ErrorCodeEmailAlreadyInUse:
print(in use)
default:
print(Create User Error :\(error!))
}
}
} else {
print(all good ... continue)
}
}
I'm having trouble figuring out how to read the FIRAuthErrorNameKey in the new version of Firebase. The following is what I have so far, but the "let errorCode = FIRAuthErrorNameKey" line is incorrect. From reading the Firebase documentation I also tried accessing the error code from the userInfo, but was unsuccessful and am out of ideas.
// Send request to Firebase to add user to register user
FIRAuth.auth()?.createUserWithEmail(emailTextField.text!, password: passwordTextField.text!, completion: { (user, error) in
// Check for errors and respond to user accordingly.
if error != nil {
let errorCode = FIRAuthErrorNameKey
switch errorCode {
case "FIRAuthErrorCodeEmailAlreadyInUse":
// Add logic accordingly
case ...:
// Add logic accordingly
case default:
// Add logic accordingly
}
}
})
解决方案 Try this. This works for me. Also, after pasting this into your project. If you need to see all the FIRAuthErrorCode
codes. Hover your mouse over .ErrorCodeInvalidEmail
then press your left mouse button and it will show you the rest.
If you have any problems let me know and ill try to help you. Good luck!
FIRAuth.auth()?.createUserWithEmail(email, password: password) { (user, error) in
if error != nil {
if let errCode = FIRAuthErrorCode(rawValue: error!._code) {
switch errCode {
case .ErrorCodeInvalidEmail:
print("invalid email")
case .ErrorCodeEmailAlreadyInUse:
print("in use")
default:
print("Create User Error: \(error!)")
}
}
} else {
print("all good... continue")
}
}
这篇关于读取Firebase身份验证错误(Firebase 3.x和Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!