我目前正在开发一个 iOS 应用程序,我想实现 Firebase 数据库。
我在处理用户创建过程中的错误时遇到了问题。我总是从开关中得到默认错误,这是我的代码:
FIRAuth.auth()?.createUser(withEmail: emailField.text!, password: passwordField.text!, completion: { (user, error) in
if (error != nil) {
if let errCode = FIRAuthErrorCode(rawValue: error!._code) {
var alertController = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.alert)
let okButton = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
(result: UIAlertAction) -> Void in
print("Error transmitted")
}
switch errCode {
case .errorCodeInvalidEmail:
print("Invalid email")
alertController = UIAlertController(title: "Error", message: "Email syntax is not correct", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(okButton)
self.present(alertController, animated: true, completion: nil)
case .errorCodeEmailAlreadyInUse:
print("Email already in use")
alertController = UIAlertController(title: "Error", message: "This email is already in use", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(okButton)
self.present(alertController, animated: true, completion: nil)
case .errorCodeWeakPassword:
print("Password weak")
alertController = UIAlertController(title: "Error", message: "Password is too weak. Please choose a password which contains at least 6 characters.", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(okButton)
self.present(alertController, animated: true, completion: nil)
default:
// ALWAYS GET HERE.
print(error)
alertController = UIAlertController(title: "Error", message: "An unknown error occured.", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(okButton)
self.present(alertController, animated: true, completion: nil)
}
}
} else {
print("User created")
let newUser = ["email": self.emailField.text!]
let firebaseNewUser = self.ref.childByAutoId()
firebaseNewUser.setValue(newUser)
}
此外,打印(错误)显示:
Optional(Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred,
print and inspect the error details for more information."
UserInfo={NSUnderlyingError=0x170257be0 {
Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)"
UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
code = 400;
errors = (
{
domain = usageLimits;
message = "Bad Request";
reason = keyExpired;
}
);
message = "Bad Request";
}}},
error_name=ERROR_INTERNAL_ERROR,
NSLocalizedDescription=An internal error has occurred, print and inspect the
error details for more information.})
有人可以帮帮我吗?
最佳答案
尝试在谷歌控制台中启用身份工具包 API。
关于swift - 创建用户 Swift 时的 Firebase 错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40484694/