Firebase 和 Swift 的重置密码问题
Reset Password Issue with Firebase and Swift
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 语句执行一些检查,但它没有。
我不知道为什么。该代码正在运行(发送密码恢复电子邮件),但该应用程序因该错误而崩溃。线索?
我找到了问题和解决方案。出于某种原因,问题在线程中。这解决了它:
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)
}
}})
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 语句执行一些检查,但它没有。
我不知道为什么。该代码正在运行(发送密码恢复电子邮件),但该应用程序因该错误而崩溃。线索?
我找到了问题和解决方案。出于某种原因,问题在线程中。这解决了它:
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)
}
}})