diff --git a/apps/ios/Shared/Model/ChatModel.swift b/apps/ios/Shared/Model/ChatModel.swift index 5cbc708bbc..8a25d57de2 100644 --- a/apps/ios/Shared/Model/ChatModel.swift +++ b/apps/ios/Shared/Model/ChatModel.swift @@ -162,7 +162,10 @@ final class ChatModel: ObservableObject { if case .rcvNew = cItem.meta.itemStatus { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { if self.chatId == cInfo.id { - Task { await apiMarkChatItemRead(cInfo, cItem) } + Task { + await apiMarkChatItemRead(cInfo, cItem) + NtfManager.shared.decNtfBadgeCount() + } } } } diff --git a/apps/ios/Shared/SimpleXApp.swift b/apps/ios/Shared/SimpleXApp.swift index 949a10bda5..8187de64ec 100644 --- a/apps/ios/Shared/SimpleXApp.swift +++ b/apps/ios/Shared/SimpleXApp.swift @@ -58,6 +58,7 @@ struct SimpleXApp: App { enteredBackground = ProcessInfo.processInfo.systemUptime } doAuthenticate = false + NtfManager.shared.setNtfBadgeCount(chatModel.totalUnreadCount()) case .active: if chatModel.chatRunning == true { ChatReceiver.shared.start() diff --git a/apps/ios/SimpleX NSE/NotificationService.swift b/apps/ios/SimpleX NSE/NotificationService.swift index e107a8bdf2..be039a65e5 100644 --- a/apps/ios/SimpleX NSE/NotificationService.swift +++ b/apps/ios/SimpleX NSE/NotificationService.swift @@ -63,8 +63,6 @@ class NotificationService: UNNotificationServiceExtension { override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { logger.debug("NotificationService.didReceive") - badgeCount = ntfBadgeCountGroupDefault.get() + 1 - ntfBadgeCountGroupDefault.set(badgeCount) setBestAttemptNtf(request.content.mutableCopy() as? UNMutableNotificationContent) self.contentHandler = contentHandler registerGroupDefaults() @@ -72,9 +70,11 @@ class NotificationService: UNNotificationServiceExtension { switch appState { case .suspended: logger.debug("NotificationService: app is suspended") + setBadgeCount() receiveNtfMessages(request, contentHandler) case .suspending: logger.debug("NotificationService: app is suspending") + setBadgeCount() Task { var state = appState for _ in 1...5 { @@ -131,6 +131,11 @@ class NotificationService: UNNotificationServiceExtension { deliverBestAttemptNtf() } + func setBadgeCount() { + badgeCount = ntfBadgeCountGroupDefault.get() + 1 + ntfBadgeCountGroupDefault.set(badgeCount) + } + func setBestAttemptNtf(_ ntf: UNMutableNotificationContent?) { logger.debug("NotificationService.setBestAttemptNtf") bestAttemptNtf = ntf