使用Swift 3检查用户身份验证错误代码

use*_*041 3 ios firebase swift firebase-authentication

在旧版本的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")
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)

FAuthenticationError似乎不再存在,文档使它看起来像被替换FIRAuthErrorNameKey.

放在FIRAuthErrorNameKey哪里FauthenticationError会导致错误:

cannot call nonfunctiontype String
Run Code Online (Sandbox Code Playgroud)

以下是我正在查看的文档:https://firebase.google.com/docs/auth/ios/errors

任何想法如何实现Swift 3中第一个代码块的功能?

Ton*_*enu 12

使用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:
                    }
            }
}
Run Code Online (Sandbox Code Playgroud)