-1

I want to clear the applicationIconBadgeNumber and keep the notification in the notification center for iOS 8 ~ 11. I have tried the code in the applicationDidBecomeActive:

UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.applicationIconBadgeNumber = -1;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];

It works at the beginning but when I try more times, I can receive the UILocalNotification but cant change theapplicationIconBadgeNumber`.

Are there any other solutions or is my usage is wrong?

Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
xuanpf
  • 25
  • 3
  • Possible duplicate of [Clear notifications badge without removing notifications](https://stackoverflow.com/questions/23674916/clear-notifications-badge-without-removing-notifications) – Kiran Sarvaiya Dec 15 '17 at 05:12
  • please check https://stackoverflow.com/questions/23674916/clear-notifications-badge-without-removing-notifications/47467746#47467746 answers in this question – Kiran Sarvaiya Dec 15 '17 at 05:12

1 Answers1

0

Instead of your code, use

if (@available(iOS 9, *)) {
    // iOS 9 (or newer) 
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
} else {
    // iOS 8
    [UIApplication sharedApplication].applicationIconBadgeNumber = -1;

}

to clear app icon badge. This will not clear the notification but counter will become zero on app icon.

You can write this code to clear count in

- (void)applicationWillEnterForeground:(UIApplication *)application

or

- (void)applicationDidBecomeActive:(UIApplication *)application
Alok Nair
  • 3,994
  • 3
  • 24
  • 30