Răsfoiți Sursa

ensure keyboard observer is removed if ChatViewController disappeared

cyberta 4 ani în urmă
părinte
comite
86f9f82051
1 a modificat fișierele cu 10 adăugiri și 2 ștergeri
  1. 10 2
      deltachat-ios/Chat/ChatViewController.swift

+ 10 - 2
deltachat-ios/Chat/ChatViewController.swift

@@ -20,6 +20,7 @@ class ChatViewController: UITableViewController {
     var dismissCancelled = false
     var foregroundObserver: Any?
     var backgroundObserver: Any?
+    var keyboardObserver: Any?
 
     lazy var isGroupChat: Bool = {
         return dcContext.getChat(chatId: chatId).isGroup
@@ -266,8 +267,6 @@ class ChatViewController: UITableViewController {
             editingBar.delegate = self
             tableView.allowsMultipleSelectionDuringEditing = true
         }
-        let notificationCenter = NotificationCenter.default
-        notificationCenter.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
     }
 
     @objc func keyboardWillShow(_ notification: Notification) {
@@ -395,6 +394,12 @@ class ChatViewController: UITableViewController {
                                        name: UIApplication.willResignActiveNotification,
                                        object: nil)
 
+        keyboardObserver = nc.addObserver(self,
+                                          selector: #selector(keyboardWillShow(_:)),
+                                          name: UIResponder.keyboardWillShowNotification,
+                                          object: nil)
+
+
         // things that do not affect the chatview
         // and are delayed after the view is displayed
         DispatchQueue.global(qos: .background).async { [weak self] in
@@ -434,6 +439,9 @@ class ChatViewController: UITableViewController {
         if let backgroundObserver = self.backgroundObserver {
             nc.removeObserver(backgroundObserver)
         }
+        if let keyboardObserver = keyboardObserver {
+            nc.removeObserver(keyboardObserver)
+        }
         audioController.stopAnyOngoingPlaying()
 
     }