Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset iOS Push Notifications Badge number in Parse?

I am using Parse iOS SDK. I have problem in resetting the badge count. I am using the tutorial(parse) code to send push notifications. I am using increment for badge, but the badge count keeps on incrementing. I am resetting the badge count in applicationDidBecomeActive: method like this,

- (void)applicationDidBecomeActive:(UIApplication *)application { 

    PFInstallation *currentInstallation = [PFInstallation currentInstallation];

    if (currentInstallation.badge != 0) {
        currentInstallation.badge = 0;
        [currentInstallation saveEventually];
    }

// ...
}

It just resets the badge number locally. But when I send the push notification next time, it just increments the previous count value and displays it. I guess the badge number in Parse server is not getting reset. Also, I tried to use [currentInstallation saveInBackground]; , but it not working too. Help

like image 881
Igor Chernyaev Avatar asked Oct 19 '22 16:10

Igor Chernyaev


1 Answers

Try leaving away the if-statement (if you don't mind unnecessary api requests):

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.badge = 0;
[currentInstallation saveEventually];

It seems that sometimes the installation.badge != 0 check fails.

This is how I solved my desynced badges.

like image 169
eschanet Avatar answered Oct 22 '22 21:10

eschanet