Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do work in timer only when in foreground
Browse files Browse the repository at this point in the history
r10s committed May 14, 2021
1 parent 09124b1 commit 1ed1353
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deltachat-ios/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -523,7 +523,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
8 changes: 5 additions & 3 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}

0 comments on commit 1ed1353

Please sign in to comment.