【问题标题】:how to get more information from firebase error?如何从 firebase 错误中获取更多信息?
【发布时间】:2016-09-17 00:12:25
【问题描述】:

我从 firebase 收到这个错误:

发生内部错误,打印并检查更多信息中的错误详细信息。

我怎么知道错误是什么??,

这是我打印错误的代码

 let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
    FIRAuth.auth()?.signInWithCredential(credential, completion: {(user, error) in
        if error != nil {
            SCLAlertView().showError("error #1", subTitle: (error?.localizedDescription)!)
            return
        }
})

【问题讨论】:

  • 只打印错误,而不是错误?.localizedDescription。 - 这至少应该为您提供更多信息,包括您已经获得的本地化描述。

标签: ios swift firebase firebase-authentication


【解决方案1】:

您可以将错误从Error转换为NSError,然后获取错误代码。这样你就可以得到 FIRAuthErrorCode。

例如:

let credential = FIRFacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
    FIRAuth.auth()?.signIn(with: credential, completion: {(user, error) in
        if error != nil {
            let castedError = error! as NSError
            let firebaseError = FIRAuthErrorCode(rawValue: castedError.code)
            if firebaseError != nil {
                switch(firebaseError!) {
                case .errorCodeWrongPassword:
                    //do something or break
                    break
                default:
                    //do something or break
                    break
                }
            }
        }
    })

检查 FIRAuthErrorCode here 中所有可能的错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    相关资源
    最近更新 更多