Browse Source

do work in timer only when in foreground

B. Petersen 4 năm trước cách đây
mục cha
commit
dddaf1a9fa

+ 1 - 1
deltachat-ios/AppDelegate.swift

@@ -517,7 +517,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.setStockTranslation(id: DC_STR_FORWARDED, localizationKey: "forwarded")
     }
 
-    private func appIsInForeground() -> Bool {
+    func appIsInForeground() -> Bool {
         switch UIApplication.shared.applicationState {
         case .background, .inactive:
             return false

+ 5 - 3
deltachat-ios/Chat/ChatViewController.swift

@@ -283,9 +283,11 @@ class ChatViewController: UITableViewController {
             timer = Timer.scheduledTimer(withTimeInterval: 60, repeats: true) { [weak self] _ in
                 //reload table
                 DispatchQueue.main.async {
-                    guard let self = self else { return }
-                    self.messageIds = self.getMessageIds()
-                    self.reloadData()
+                    guard let self = self, let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
+                    if appDelegate.appIsInForeground() {
+                        self.messageIds = self.getMessageIds()
+                        self.reloadData()
+                    }
                 }
             }
         }