Push notification badge reset count
13,139
Solution 1
To clear the badge count whenever the application becomes active, simply include your line of code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
In the AppDelegate.m
file's applicationDidBecomeActive
delegate method.
applicationDidFinishLaunchingWithOptions
is only called on the initial launch, and does not get called again when the application goes to the background and back to the foreground.
Solution 2
For Swift 3.0
//AppleDelgate.swift
func applicationDidBecomeActive(_ application: UIApplication) {
//....
application.applicationIconBadgeNumber = 0
//....
}
![Automator21](https://i.stack.imgur.com/z8I4G.png?s=256&g=1)
Author by
Automator21
Updated on June 07, 2022Comments
-
Automator21 about 2 years
I'm using PushBot as my push notification service, my issue is how do I reset the badge count. I've search and read to use this line of code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
The only way the badge count gets reset is if I quit the app from running on the mulit-task bar and launch the app again, any help is greatly appreciated. Thanks,
-
Brad Adams almost 8 yearsThis appears to be working, but the next time I receive a a notification, the count isn't 1. It's the count that was removed + 1 (the total notification count since the app was installed). Any ideas?
-
Terence over 7 yearsI'm also getting "count that was removed" + 1. Any help? I've put that code in
applicationDidBecomeActive
ANDapplicationDidFinishLaunchingWithOptions
-
Marcus Adams over 7 yearsAre you talking about the badge number in a remote notification? That's up to you to set on the server when you send the remote notification.