Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用FirebaseAuth错误代码?_Ios_Swift_Firebase_Firebase Authentication - Fatal编程技术网

Ios 如何使用FirebaseAuth错误代码?

Ios 如何使用FirebaseAuth错误代码?,ios,swift,firebase,firebase-authentication,Ios,Swift,Firebase,Firebase Authentication,我试图在Firebase中使用authorCode,但我不断收到错误。这是我的密码: private func handleErrors(err: NSError, loginHandler: LoginHandler?) { if let errCode = AuthErrorCode(rawValue: err.code) { switch errCode { case .errorCodeWrongPassword: //Enum case

我试图在Firebase中使用
authorCode
,但我不断收到错误。这是我的密码:

private func handleErrors(err: NSError, loginHandler: LoginHandler?) {

    if let errCode = AuthErrorCode(rawValue: err.code) {

        switch errCode {

        case .errorCodeWrongPassword:  //Enum case 'errorCodeWrongPassword' not found in type 'AuthErrorCode'
            loginHandler?(LoginErrorCode.WRONG_PASSWORD)
            break

        case .errorCodeInvalidEmail:  //Enum case 'errorCodeInvalidEmail' not found in type 'AuthErrorCode'
            loginHandler?(LoginErrorCode.INVALID_EMAIL)
            break

        case .errorCodeUserNotFound:  //Enum case 'errorCodeUserNotFound' not found in type 'AuthErrorCode'
            loginHandler?(LoginErrorCode.USER_NOT_FOUND)
            break

        case .errorCodeEmailAlreadyInUse:  //Enum case 'errorCodeEmailAlreadyInUse' not found in type 'AuthErrorCode'
            loginHandler?(LoginErrorCode.EMAIL_ALREADY_IN_USE)
            break

        case .errorCodeWeakPassword:  //Enum case 'errorCodeWeakPassword' not found in type 'AuthErrorCode'
            loginHandler?(LoginErrorCode.WEAK_PASSWORD)
            break

        default:
            loginHandler?(LoginErrorCode.PROBLEM_CONNECTING)
            break

        }

    }

}
有人知道我做错了什么吗?如果您没有在我的代码中看到错误,则它们是:

Enum case 'errorCodeWrongPassword' not found in type 'AuthErrorCode'

Enum case 'errorCodeInvalidEmail' not found in type 'AuthErrorCode'

Enum case 'errorCodeUserNotFound' not found in type 'AuthErrorCode'

Enum case 'errorCodeEmailAlreadyInUse' not found in type 'AuthErrorCode'

Enum case 'errorCodeWeakPassword' not found in type 'AuthErrorCode'

如果你们有任何想法,请告诉我

它们在Swift中作为
AuthErrorCode.weakPassword
导入,例如:从所有大小写值中删除
errorCode

private func handleErrors(err: NSError, loginHandler: LoginHandler?) {

    guard let errCode = AuthErrorCode(rawValue: err.code)
        else { return }

        switch errCode {

        case .wrongPassword:
            loginHandler?(LoginErrorCode.WRONG_PASSWORD) // Transform to wrongPassword
        case .invalidEmail:
            loginHandler?(LoginErrorCode.INVALID_EMAIL)
        case .userNotFound:
            loginHandler?(LoginErrorCode.USER_NOT_FOUND)
        case .emailAlreadyInUse:
            loginHandler?(LoginErrorCode.EMAIL_ALREADY_IN_USE)
        case .weakPassword:
            loginHandler?(LoginErrorCode.WEAK_PASSWORD)
        default:
            loginHandler?(LoginErrorCode.PROBLEM_CONNECTING)
        }
  
}


快速建议:

  • 不要在switch语句中使用
    break
    ,它们在案例完成后默认会中断(
    fallthrough
    允许您在匹配后检查每个案例)
  • 切换
    NSError
    以查看
    Error
    (如果要切换到Error read,Firebase将使用NSError)
  • LoginErrorCode是您的自定义类吗?考虑切换到SWIFT > = 3语法的情况(下骆驼案件)

“为错误切换NSError”-默认错误类没有代码变量。Firebase仍然使用NSError,因此您应该使用NSError。我知道,但你提到过使用Error类而不是NSError,后者在FirebaseAuthAnswer中使用,并且已经用可能的解决方法进行了更新