嘿,有人能告诉我如何处理吗?我尝试了很多,但如果我纠正了一个错误,另一个错误就会出现...... 提前致谢
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")
}
答案 0 :(得分:0)
您可以桥接到 NSError
,然后基于 AuthErrorCode
创建 error.code
:
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
种可能性中的几种 - 它们的列表非常广泛。