Skip to content

Commit

Permalink
duplicate app-icon badge counter to chat's tab-bar-item
Browse files Browse the repository at this point in the history
this also resets the counter on app start,
maybe fixing some rare bugs where the counter is wrong on the app icon
  • Loading branch information
r10s committed Apr 6, 2024
1 parent 71a4a27 commit 3d9d7ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions deltachat-ios/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
logger.info("➡️ applicationDidBecomeActive")
UserDefaults.setMainIoRunning()
applicationInForeground = true
NotificationManager.updateApplicationIconBadge()
}

func applicationWillResignActive(_: UIApplication) {
Expand Down
10 changes: 9 additions & 1 deletion deltachat-ios/Helper/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 3d9d7ac

Please sign in to comment.