读取 Firebase 身份验证错误(Firebase 3.x 和 Swift) [英] Reading Firebase Auth Error Thrown (Firebase 3.x and Swift)

查看:20
本文介绍了读取 Firebase 身份验证错误(Firebase 3.x 和 Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何在新版 Firebase 中读取 FIRAuthErrorNameKey.以下是我到目前为止所拥有的,但let errorCode = FIRAuthErrorNameKey"行不正确.通过阅读 Firebase 文档,我也尝试从 userInfo 访问错误代码,但是没有成功并且没有想法.

I'm having trouble figuring out how to read the FIRAuthErrorNameKey in the new version of Firebase. The following is what I have so far, but the "let errorCode = FIRAuthErrorNameKey" line is incorrect. From reading the Firebase documentation I also tried accessing the error code from the userInfo, but was unsuccessful and am out of ideas.

 // Send request to Firebase to add user to register user
 FIRAuth.auth()?.createUserWithEmail(emailTextField.text!, password: passwordTextField.text!, completion: { (user, error) in

        // Check for errors and respond to user accordingly.
        if error != nil {

            let errorCode = FIRAuthErrorNameKey

            switch errorCode {

            case "FIRAuthErrorCodeEmailAlreadyInUse":

                // Add logic accordingly

            case ...:

               // Add logic accordingly

            case default:

              // Add logic accordingly
            }
        }
 })

推荐答案

试试这个.这对我有用.此外,将其粘贴到您的项目中后.如果您需要查看所有 FIRAuthErrorCode 代码.将鼠标悬停在 .ErrorCodeInvalidEmail 上,然后按下鼠标左键,它会显示其余部分.

Try this. This works for me. Also, after pasting this into your project. If you need to see all the FIRAuthErrorCode codes. Hover your mouse over .ErrorCodeInvalidEmail then press your left mouse button and it will show you the rest.

如果您有任何问题,请告诉我,我会尽力帮助您.祝你好运!

If you have any problems let me know and ill try to help you. Good luck!

        FIRAuth.auth()?.createUserWithEmail(email, password: password) { (user, error) in

            if error != nil {

                if let errCode = FIRAuthErrorCode(rawValue: error!._code) {

                    switch errCode {
                        case .ErrorCodeInvalidEmail:
                            print("invalid email")
                        case .ErrorCodeEmailAlreadyInUse:
                            print("in use")
                        default:
                            print("Create User Error: (error!)")
                    }
                }

            } else {
                print("all good... continue")
            }
        }

这篇关于读取 Firebase 身份验证错误(Firebase 3.x 和 Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆