Authenticator
クラスのsendEmailForPasswordRecovery
メソッドはasynchronous
コールを実装しており、パスワード回復のためにfirebase
ユーザーに電子メールを送信します。即時の非同期呼び出し動作とメインキューを理解しようとしました
func sendEmailForPasswordRecovery(email: String, completion: CallBackWithError) {
FIRAuth.auth()?.sendPasswordResetWithEmail(email, completion: { (error: NSError?) in
completion(error)
})
}
私は完了ブロックは、単純にこの関数を呼び出すUIViewController
Authenticator().sendEmailForPasswordRecovery(email, completion: { (error: NSError?) in
print("operation completed. error: \(error)")
self.completion?()
})
からこのfunction
を呼び出しています。それは単ににpopUpビュー、およびフェードアウトを隠しblurEffectとはその親ビューからそれを削除します。
しかし、Authenticator().sendEmailForPasswordRecovery
が実行されると、コンソールでエラーが発生していないことがわかります。しかしpopUpビューは40〜50秒後に消えてしまいます。しかし、私がdispatch_async
内に完了をラップすると、私はすぐに私の結果を得る。
Authenticator().sendEmailForPasswordRecovery(email, completion: { (error: NSError?) in
// self.completion?() <----- this was causing delay
dispatch_async(dispatch_get_main_queue(), {
self.completion?() <------ Now it updates immidiately
})
})
Firebase sendPasswordResetWithEmail
署名有する:
public func sendPasswordResetWithEmail(email: String, completion: FIRSendPasswordResetCallback?)
を、それが必要に応じ
@param完了を言います。 要求が終了したときに呼び出されるブロック。今後メインスレッドで非同期に を呼び出します。ポップアップが一定の最初の場所での遅延とはどのよう
dispatch_assync
はimmidiately仕事をしてくれた後に消えたなぜ私が理解しない何
です。ビューをアニメーション化する
簡単な提案 - iOS開発の同時性を扱うシステムであるGrand Central Dispatch(GCD)について読むことをお勧めします。 –
いつ完了変数を設定しますか?最初のケースで正しく設定されていることを確認していますか? removeForgotPasswordScreenにブレークポイントを追加して、いつ実際に呼び出されたか、そしてどのスレッドかを確認します。 – fishinear
@MattLeFleurご提案ありがとうございます。それは非常に有用でした。 – Ccr