diff --git a/deltachat-ios/AppDelegate.swift b/deltachat-ios/AppDelegate.swift index 9c8ff3cf7..d73d50b9d 100644 --- a/deltachat-ios/AppDelegate.swift +++ b/deltachat-ios/AppDelegate.swift @@ -284,6 +284,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD logger.info("➡️ applicationDidBecomeActive") UserDefaults.setMainIoRunning() applicationInForeground = true + NotificationManager.updateBadgeCounters() } func applicationWillResignActive(_: UIApplication) { diff --git a/deltachat-ios/Controller/Settings/SettingsViewController.swift b/deltachat-ios/Controller/Settings/SettingsViewController.swift index c1244c369..dc0d56835 100644 --- a/deltachat-ios/Controller/Settings/SettingsViewController.swift +++ b/deltachat-ios/Controller/Settings/SettingsViewController.swift @@ -246,7 +246,7 @@ internal final class SettingsViewController: UITableViewController { NotificationManager.removeAllNotifications() } UserDefaults.standard.synchronize() - NotificationManager.updateApplicationIconBadge(forceZero: !sender.isOn) + NotificationManager.updateBadgeCounters(forceZero: !sender.isOn) } // MARK: - updates diff --git a/deltachat-ios/Coordinator/AppCoordinator.swift b/deltachat-ios/Coordinator/AppCoordinator.swift index d4db67a57..972b0092a 100644 --- a/deltachat-ios/Coordinator/AppCoordinator.swift +++ b/deltachat-ios/Coordinator/AppCoordinator.swift @@ -230,7 +230,7 @@ class AppCoordinator: NSObject { // the applicationIconBadgeNumber is remembered by the system even on reinstalls (just tested on ios 13.3.1), // to avoid appearing an old number of a previous installation, we reset the counter manually. // but even when this changes in ios, we need the reset as we allow account-deletion also in-app. - NotificationManager.updateApplicationIconBadge(forceZero: true) + NotificationManager.updateBadgeCounters(forceZero: true) } func presentTabBarController() { @@ -271,6 +271,7 @@ class AppCoordinator: NSObject { createChatsNavigationController(), createSettingsNavigationController()], animated: false) presentTabBarController() + NotificationManager.updateBadgeCounters() } } diff --git a/deltachat-ios/Helper/NotificationManager.swift b/deltachat-ios/Helper/NotificationManager.swift index e9161cf89..8d871ff23 100644 --- a/deltachat-ios/Helper/NotificationManager.swift +++ b/deltachat-ios/Helper/NotificationManager.swift @@ -22,9 +22,19 @@ public class NotificationManager { dcContext = dcAccounts.getSelected() } - public static func updateApplicationIconBadge(forceZero: Bool = false) { + public static func updateBadgeCounters(forceZero: Bool = false) { DispatchQueue.main.async { - UIApplication.shared.applicationIconBadgeNumber = forceZero ? 0 : DcAccounts.shared.getFreshMessageCount() + let number = forceZero ? 0 : DcAccounts.shared.getFreshMessageCount() + + // update badge counter on iOS homescreen + UIApplication.shared.applicationIconBadgeNumber = number + + // update badge counter on our tabbar + if let appDelegate = UIApplication.shared.delegate as? AppDelegate, + let appCoordinator = appDelegate.appCoordinator, + let chatsNavigationController = appCoordinator.tabBarController.viewControllers?[appCoordinator.chatsTab] { + chatsNavigationController.tabBarItem.badgeValue = number > 0 ? "\(number)" : nil + } } } @@ -55,7 +65,7 @@ public class NotificationManager { nc.removeDeliveredNotifications(withIdentifiers: toRemove) } - NotificationManager.updateApplicationIconBadge() + NotificationManager.updateBadgeCounters() } } @@ -65,7 +75,7 @@ public class NotificationManager { object: nil, queue: OperationQueue.main ) { _ in if !UserDefaults.standard.bool(forKey: "notifications_disabled") { - NotificationManager.updateApplicationIconBadge() + NotificationManager.updateBadgeCounters() } }