From 3d9d7ac95884d2c09026c126cf916576478865b2 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 6 Apr 2024 14:06:43 +0200 Subject: [PATCH] duplicate app-icon badge counter to chat's tab-bar-item this also resets the counter on app start, maybe fixing some rare bugs where the counter is wrong on the app icon --- deltachat-ios/AppDelegate.swift | 1 + deltachat-ios/Helper/NotificationManager.swift | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/deltachat-ios/AppDelegate.swift b/deltachat-ios/AppDelegate.swift index 9c8ff3cf7..e12e1eeb5 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.updateApplicationIconBadge() } func applicationWillResignActive(_: UIApplication) { diff --git a/deltachat-ios/Helper/NotificationManager.swift b/deltachat-ios/Helper/NotificationManager.swift index e9161cf89..1bc348b97 100644 --- a/deltachat-ios/Helper/NotificationManager.swift +++ b/deltachat-ios/Helper/NotificationManager.swift @@ -24,7 +24,15 @@ public class NotificationManager { public static func updateApplicationIconBadge(forceZero: Bool = false) { DispatchQueue.main.async { - UIApplication.shared.applicationIconBadgeNumber = forceZero ? 0 : DcAccounts.shared.getFreshMessageCount() + let number = forceZero ? 0 : DcAccounts.shared.getFreshMessageCount() + + UIApplication.shared.applicationIconBadgeNumber = number + + 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 + } } }