Skip to content

Commit e92e4b7

Browse files
committed
[trello.com/c/3w2UROLD] fix remote notification budge update
1 parent c7b0a0c commit e92e4b7

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

Adamant/App/AppDelegate.swift

-4
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,9 @@ extension AppDelegate {
507507
return
508508
}
509509

510-
notificationsService.startBackgroundBatchNotifications()
511-
512510
Task {
513511
let results = await fetchBackgroundData(notificationsService: notificationsService)
514512

515-
notificationsService.stopBackgroundBatchNotifications()
516-
517513
for result in results {
518514
switch result {
519515
case .newData:

Adamant/ServiceProtocols/NotificationsService.swift

-4
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,4 @@ protocol NotificationsService: AnyObject, Sendable {
262262

263263
func removeAllPendingNotificationRequests()
264264
func removeAllDeliveredNotifications()
265-
266-
// MARK: Background batch notifications
267-
func startBackgroundBatchNotifications()
268-
func stopBackgroundBatchNotifications()
269265
}

Adamant/Services/AdamantNotificationService.swift

+9-18
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ final class AdamantNotificationsService: NSObject, NotificationsService {
6565
private(set) var inAppVibrate: Bool = true
6666
private(set) var inAppToasts: Bool = true
6767

68-
private var isBackgroundSession = false
6968
private var backgroundNotifications = 0
7069
private var subscriptions = Set<AnyCancellable>()
7170

@@ -91,6 +90,13 @@ final class AdamantNotificationsService: NSObject, NotificationsService {
9190
.notifications(named: .AdamantAccountService.userLoggedOut, object: nil)
9291
.sink { @MainActor [weak self] _ in self?.onUserLoggedOut() }
9392
.store(in: &subscriptions)
93+
94+
NotificationCenter.default
95+
.notifications(named: UIApplication.didBecomeActiveNotification)
96+
.sink { @MainActor [weak self] _ in
97+
self?.backgroundNotifications = 0
98+
}
99+
.store(in: &subscriptions)
94100
}
95101

96102
func setInAppSound(_ value: Bool) {
@@ -249,12 +255,9 @@ extension AdamantNotificationsService {
249255

250256
if let number = type.badge {
251257
DispatchQueue.onMainThreadSyncSafe {
252-
content.badge = NSNumber(value: UIApplication.shared.applicationIconBadgeNumber + backgroundNotifications + number)
253-
}
254-
255-
if isBackgroundSession {
256-
backgroundNotifications += number
258+
content.badge = NSNumber(value: customBadgeNumber + backgroundNotifications + number)
257259
}
260+
backgroundNotifications += number
258261
}
259262

260263
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
@@ -300,18 +303,6 @@ extension AdamantNotificationsService {
300303
}
301304
}
302305

303-
// MARK: - Background batch notifications
304-
extension AdamantNotificationsService {
305-
func startBackgroundBatchNotifications() {
306-
isBackgroundSession = true
307-
backgroundNotifications = 0
308-
}
309-
310-
func stopBackgroundBatchNotifications() {
311-
isBackgroundSession = false
312-
backgroundNotifications = 0
313-
}
314-
}
315306

316307
extension AdamantNotificationsService {
317308
fileprivate func onUserLoggedIn() {

0 commit comments

Comments
 (0)