3

When i am about to send a push notification to my app from parse, it has an option to increment the app badge. If i turn it on and send the notification, the apps badge will keep on climbing higher and higher. How do i get the badge to go back to 0? See Image here.

Note: If the answer is in code, please answer in swift.

enter image description here

3 Answers 3

9

Swift

UIApplication.sharedApplication().applicationIconBadgeNumber = 0

Objective-C

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

UPDATE

to let PARSE know that it has to reset the counter do the following (this also resets the local badge count on the device):

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge != 0) {
  currentInstallation.badge = 0;
  [currentInstallation saveEventually];
}
2
  • 1
    I am doing this in my appDelegate didFinishLaunchingWithOptions and in the app didBecomeActive and this works temporarily but then if I receive a new notification, the app badge does not read 1 as expected but instead 1 is added to the previous badge number that had been cleared. Any info on this? Sep 17, 2015 at 16:00
  • also have same problem
    – moonvader
    Dec 15, 2015 at 12:30
4
   PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.badge = 0;
[currentInstallation saveEventually];

Try this.

Code ,above mentioned, change the badge count of app but not update it on server. So when app receive new notification, previous badge number is incremented.

1

Updated answer for Swift 4:

UIApplication.shared.applicationIconBadgeNumber = 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.