I am working with push notifications. When I get a notification it comes with 2 button, view and close. If I click on view it opens the app and when I click the close button it does nothing but a badge number appears on the app icon. Then when I open my app again that badge number should disappear but it doesn't. How can I remove that badge number if user clicks on app icon? Thanx
Asked
Active
Viewed 1.6k times
2 Answers
40
put the following code somewhere in your applicationDidFinishLaunching or applicationDidBecomeActive.
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

amattn
- 10,045
- 1
- 36
- 33
1
What you could do is omit the badge
key from your remote notification so that any badge number currently shown is removed. If you want a badge to show up if the user taps View, you can set a badge number using [UIApplication sharedApplication].applicationIconBadgeNumber
.
But I'm not sure why you'd want to do this.

Daniel Dickison
- 21,832
- 13
- 69
- 89
-
what if user click close button? i have done that view button clicked part before. – Piscean Feb 28 '11 at 18:31
-
The notification will remove the badge, so there wil be no badge if the user taps Close. As mentioned [here](http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html), "If \[the `badge` property\] is absent, any badge number currently shown is removed." – Daniel Dickison Feb 28 '11 at 19:31