All notifications disappearing after opening one of them

后端 未结 3 1348
鱼传尺愫
鱼传尺愫 2020-12-10 02:19

I have a server that sends me push notifications and let\'s say that I have 5 notifications on my phone. If I open one of them all other notifications disappears. I want onl

相关标签:
3条回答
  • 2020-12-10 02:59

    The solution is to set the applicationIconBadgeNumber to the real number of notifications the user has in the notification center. I made a function for this:

    func updateIconBadge() {
        UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
            DispatchQueue.main.async {
                UIApplication.shared.applicationIconBadgeNumber = notifications.count
            }
        }
    }
    

    For more info (like where to call to this function) you may want to check my original answer here: https://stackoverflow.com/a/54296486/8157190

    0 讨论(0)
  • 2020-12-10 03:01

    If you use OneSignal SDK in your app, and you have the problem of disappearing notifications after opening one, you must add key OneSignal_disable_badge_clearing to the Info.plist file in Xcode, as a Boolean type set to YES.

    More info here https://documentation.onesignal.com/docs/badges

    0 讨论(0)
  • 2020-12-10 03:07

    By setting the applicationIconBadgeNumber to 0, you also remove every notification from the notification center.

    This has also been discussed here: iOS application: how to clear notifications?

    Furthermore, it is not possible to programmatically remove a single notification, but from iOS8 on, the OS will handle this for you when a user taps a single notification. This has also been discussed here: Remove single remote notification from Notification Center

    0 讨论(0)
提交回复
热议问题