Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push notification badge reset count

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,

like image 552
Automator21 Avatar asked Aug 06 '13 18:08

Automator21


People also ask

How do I clear badge count on iPhone?

Go to Settings and open Notifications. Scroll down and tap on Messages. To disable notifications altogether, toggle off Allow Notifications. To remove badges, turn off the toggle next to Badges.

How do I count the number of notifications for an icon?

It even has a way to display Badge Count in Pure Android devices desktop. Updating the Badge Count in the application icon is as easy as calling: int badgeCount = 1; ShortcutBadger. applyCount(context, badgeCount);

What is iOS notification badge count?

The iOS badge count displays the number of unread notifications within your application, taking the form of a red circle in the upper-right hand corner of the app icon. In recent years, badging has come to be an effective means for re-engaging app users.


2 Answers

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.

like image 109
Marcus Adams Avatar answered Sep 28 '22 08:09

Marcus Adams


For Swift 3.0

//AppleDelgate.swift
 func applicationDidBecomeActive(_ application: UIApplication) {
        //....
        application.applicationIconBadgeNumber = 0
       //....
}
like image 28
Jitendra Kulkarni Avatar answered Sep 28 '22 09:09

Jitendra Kulkarni