Clear notifications badge without removing notifications

后端 未结 3 789
情歌与酒
情歌与酒 2021-01-12 16:13

In my app, I\'m receiving push notifications with badge number set to one. When app will start, it should set badges count to 0, so I\'m using:

[[UIApplicat         


        
相关标签:
3条回答
  • 2021-01-12 16:53

    With iOS9 directly setting badge to negative still clears notifications. You must fire empty UILocalNotification with negative badgenumber to achieve this.

    let ln = UILocalNotification()
    ln.applicationIconBadgeNumber = -1
    UIApplication.sharedApplication().presentLocalNotificationNow(ln)
    
    0 讨论(0)
  • 2021-01-12 17:04

    @feb for ios 9+ you need to set 0 not -1 for that you need to add version condition

        if #available(iOS 9.0, *) {
            UIApplication.shared.applicationIconBadgeNumber = 0
        }else{
            UIApplication.sharedApplication().applicationIconBadgeNumber = -1
        }
    
    0 讨论(0)
  • 2021-01-12 17:12

    According to this topic:

    How to clear badge number while preserving notification center

    setting:

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1];
    

    should do the trick.

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