【问题标题】:Swift - Google Firebase Authentication with EmailSwift - 使用电子邮件的 Google Firebase 身份验证
【发布时间】:2017-05-08 00:57:21
【问题描述】:

我正在尝试使用电子邮件运行 Google Firebase 身份验证的示例。当我尝试https://github.com/firebase/quickstart-ios/blob/master/authentication/AuthenticationExampleSwift/EmailViewController.swift 的电子邮件示例时,我在项目中遇到错误。

我的代码如下所示:

@IBAction func loginButtonTapped(_ sender: AnyObject) {
    if let email = self.userEmailTextField.text, let password = self.userPasswordTextField.text {
        showSpinner({
            // [START headless_email_auth]
            FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in
                // [START_EXCLUDE]
                self.hideSpinner({
                    if let error = error {
                        self.showMessagePrompt(error.localizedDescription)
                        return
                    }
                    self.navigationController!.popViewController(animated: true)
                })
                // [END_EXCLUDE]
            }
            // [END headless_email_auth]
        })
    } else {
        self.showMessagePrompt("email/password can't be empty")
    }
}

我在showSpinner({...}) 和最后在self.showMessagePrompt("email/password can't be empty") 收到错误:

但是,showMessagePrompt 末尾的错误并没有出现在 self.showMessagePrompt 几行之前。可能和我的 Swift 版本有关,我尝试转换为 3,但之后我的整个项目就坏了。

【问题讨论】:

    标签: ios swift firebase firebase-authentication


    【解决方案1】:

    因为在那个 quickstart-ios 中,他们使用了 UIViewController+Alerts.h 文件的 bridging-header,该文件不是您实现的,也不是您在项目中添加的。

    因此,一种解决方案是在您的视图控制器中使用UIViewController+Alerts.h 作为桥接头,或者删除/修改您的代码,类似于此代码..

     @IBAction func loginButtonTapped(_ sender: AnyObject) {
        if let email = self.userEmailTextField.text, let password = self.userPasswordTextField.text {
            // [START headless_email_auth]
            FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in
                // [START_EXCLUDE]
    
                if let error = error {
                    print(error.localizedDescription)
                    //show alert
                    return
                }
                self.navigationController!.popViewController(animated: true)
    
                // [END_EXCLUDE]
            }
            // [END headless_email_auth]
        } else {
           print("email/password can't be empty")
           //show alert
        }
     }
    

    你可以找到UIViewController+Alerts.hUIViewController+Alerts.m文件here

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 2018-11-11
    • 2018-02-10
    • 1970-01-01
    • 2021-03-26
    • 2016-10-25
    • 2017-10-26
    相关资源
    最近更新 更多