【问题标题】:Reset Password Issue with Firebase and Swift使用 Firebase 和 Swift 重置密码问题
【发布时间】:2016-10-04 08:49:21
【问题描述】:

在 Firebase 更新其后端后,我遇到了重置密码的问题。由于某种原因,应用程序崩溃(即使它发送带有重置密码的电子邮件)。这是我得到的控制台错误:

2016-06-04 12:32:21.883 NewApp[47459:27055361] *** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/Keyboard/UIKeyboardTaskQueue.m:386
2016-06-04 12:32:21.890 NewApp[47459:27055361] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
libc++abi.dylib: terminating with uncaught exception of type NSException

在 ResetPasswordVC 中我有以下内容:

 @IBAction func resetPasswordTapped(sender: ButtonWhite) {

    SVProgressHUD.showWithStatus("Please, wait...")
    SVProgressHUD.setDefaultMaskType(.Gradient)

    let email = emailTextField.text

    if email != "" {

        FIRAuth.auth()?.sendPasswordResetWithEmail(email!, completion: { (error) in

            if error != nil {

                // Error - Unidentified Email
                SVProgressHUD.dismiss()
                showAlert(title: "Unidentified Email Address", msg: "Please, re-enter the email you have registered with.", actionButton: "OK", viewController: self)

            } else {

                // Success - Sent recovery email

                SVProgressHUD.dismiss()

                let alertController = UIAlertController(title: "Email Sent", message: "An email has been sent. Please, check your email now.", preferredStyle: .Alert)
                alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: { action in

                    self.dismissViewControllerAnimated(true, completion: nil)
                }))
                self.presentViewController(alertController, animated: true, completion: nil)
            }

        })

    } else {

        SVProgressHUD.dismiss()
        showAlert(title: "Error!", msg: "Email is required in order to reset your password. Please, enter your email. ", actionButton: "OK", viewController: self)
    } 
}

我已经用断点对其进行了测试以查看流程,它到达FIRAuth.auth()?.sendPasswordResetWithEmail(email!, completion: { (error) in,其中电子邮件有一个值,它应该基于它执行一些检查 if/else 语句,但它没有。

我不知道为什么。该代码正在运行(发送密码恢复电子邮件),但应用程序因该错误而崩溃。线索?

【问题讨论】:

  • 我在 Objective-C 中也遇到了这个错误。看起来他们的重置密码 API 的完成处理程序没有返回到主线程,这与他们的其他 API 不同。

标签: swift firebase passwords recovery


【解决方案1】:

我找到了问题和解决方案。出于某种原因,问题出在线程内。这解决了它:

            FIRAuth.auth()?.sendPasswordResetWithEmail(email!, completion: { (error) in


            NSOperationQueue.mainQueue().addOperationWithBlock {

            if error != nil {

                // Error - Unidentified Email
                SVProgressHUD.dismiss()
                showAlert(title: "Unidentified Email Address", msg: "Please, re-enter the email you have registered with.", actionButton: "OK", viewController: self)

            } else {

                // Success - Sends recovery email

                SVProgressHUD.dismiss()

                let alertController = UIAlertController(title: "Email Sent", message: "An email has been sent. Please, check your email now.", preferredStyle: .Alert)
                alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: { action in

                    self.dismissViewControllerAnimated(true, completion: nil)
                }))
                self.presentViewController(alertController, animated: true, completion: nil)
            }

            }})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-15
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2023-03-25
    • 1970-01-01
    • 2018-10-13
    相关资源
    最近更新 更多