使用Firebase和Swift重置密码问题

时间:2016-06-04 09:43:05

标签: swift firebase passwords recovery

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,其中电子邮件具有值,如果/ else语句,它应该基于它执行一些检查,但它不会。

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

1 个答案:

答案 0 :(得分:4)

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

            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)
            }

            }})