IceCubesApp icon indicating copy to clipboard operation
IceCubesApp copied to clipboard

Bug: Notification count incorrect in many cases

Open blueturtleai opened this issue 1 year ago • 5 comments

Environment:

  • OS: iOS 17.2
  • IceCubesApp version: 1.10.10

Description

In many cases the notification counter shows the double amount of notifications. For example it shows 2, but when I check the notification tab, there is only 1 new notification. I also only get 1 push alert. I have got several accounts, maybe the problem is connected to that.

blueturtleai avatar Jan 03 '24 17:01 blueturtleai

I observed this now for some days. My impression is, that it only happens, if the app is in foreground when the notification arrives. Not sure, if this helps and if it is even possible.

blueturtleai avatar Jan 09 '24 18:01 blueturtleai

Iā€˜m more and more sure, that duplicate count only occurs, if the app is in foreground.

To better understand, if this could really happen, I read a bit about iOS notifications. And here comes my theory: it seems, your app listens to remote notifications. Is there a second listener for foreground notifications? If so, both listeners could be triggered, which leads to a duplicate count.

I’m not an iOS developer, so this is only a wild guess šŸ˜€. Would like to hear your opinion.

blueturtleai avatar Jan 13 '24 18:01 blueturtleai

I'll check everywhere I increase the count when I'll work on this issue. Thanks for all the detail it'll really make it easy to solve!

Dimillian avatar Jan 13 '24 20:01 Dimillian

I had now a look at the code and I think I understand now why it happens:

StreamWatcher.swift 101 self.unreadNotificationsCount += 1

NotificationService.swift 73 currentCount += 1 preferences.notificationsCount[token] = currentCount

AppView.swift 103 return watcher.unreadNotificationsCount + (userPreferences.notificationsCount[token] ?? 0)

If the app is in foreground, StreamWatcher AND NotificationService are triggered. watcher.unreadNotificationsCount and userPreferences.notificationsCount are increased by 1. Both values are added and displayed as badge in AppView. To fix it, unreadNotificationsCount shouldn't be increased, if the app is in foreground.

Not sure, if this the right way to fix it, but I think I have identified the cause for this issue correctly. At least I hope so šŸ˜€.

blueturtleai avatar Jan 21 '24 15:01 blueturtleai