All notifications disappearing after opening one of them

后端 未结 3 1359
鱼传尺愫
鱼传尺愫 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条回答
  •  -上瘾入骨i
    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

提交回复
热议问题