在旧版本的 Swift 中,以下代码可用于检查用户身份验证错误:
if (error != nil) {
// an error occurred while attempting login
if let errorCode = FAuthenticationError(rawValue: error.code) {
switch (errorCode) {
case .UserDoesNotExist:
println("Handle invalid user")
case .InvalidEmail:
println("Handle invalid email")
case .InvalidPassword:
println("Handle invalid password")
default:
println("Handle default situation")
}
}
}
FAuthenticationError
似乎不再存在,并且文档使它看起来已被替换为 FIRAuthErrorNameKey
。
将 FIRAuthErrorNameKey
放在 FauthenticationError
的位置会导致错误:
cannot call nonfunctiontype String
这是我正在查看的文档:https://firebase.google.com/docs/auth/ios/errors
有什么想法可以实现 Swift 3 中第一段代码的功能吗?
最佳答案
使用 FIRAuthErrorCode
- 它是一个 int 枚举
enum FIRAuthErrorCode { FIRAuthErrorCodeInvalidCustomToken = 17000, FIRAuthErrorCodeCustomTokenMismatch = 17002, FIRAuthErrorCodeInvalidCredential = 17004, FIRAuthErrorCodeUserDisabled = 17005,
来自这里:https://firebase.google.com/docs/reference/ios/firebaseauth/interface_f_i_r_auth_errors
尝试这样使用:
if (error != nil) {
// an error occurred while attempting login
if let errCode = FIRAuthErrorCode(rawValue: (error?._code)!) {
switch errCode {
case .errorCodeEmailAlreadyInUse:
...
case .errorCodeInvalidEmail:
...
case .errorCodeWrongPassword:
}
}
}
关于ios - 使用 Swift 3 检查用户身份验证错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39691680/