How can I remove the badge number if I click on close button in push notification?

Piscean picture Piscean · Feb 28, 2011 · Viewed 15.7k times · Source

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

Answer

amattn picture amattn · Feb 28, 2011

put the following code somewhere in your applicationDidFinishLaunching or applicationDidBecomeActive.

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;