Geek
Geek

Reputation: 8320

Application icon badge is not displayed

I set app icon badge using

[UIApplication sharedApplication].applicationIconBadgeNumber = ...;

I change its value on multiples classes. In one of the classes I ma having issue that

NSLog(@"App icon badge : %d", [UIApplication sharedApplication].applicationIconBadgeNumber);

prints some value.e.g. 4. But if I put app in background then there is no badge on icon. It should display badge 4.

I also change badge value in another class. In that it sets correct value and putting app in background shows correct value.

What happens is I am in controller, in which setting of badge value works, and log current badge value then it gives the correct value and putting app in background also shows correct value. But then if go to another controller, in which settings of badge is not working, and log badge value then it always prints 0.

Upvotes: 0

Views: 324

Answers (3)

Geek
Geek

Reputation: 8320

I solved it. It was due to below code of parse.

PFInstallation * currentInstallation = [PFInstallation currentInstallation];
currentInstallation.badge = 0;
[currentInstallation saveEventually:^(BOOL succeeded, NSError *error) {
    if (error)
    {
        ALog(@"Parse error in setting badge on installation object. Error : %@", error);
    }
}];

After below line it was setting app icon badge to 0.

currentInstallation.badge = 0;

Upvotes: 0

Stranger
Stranger

Reputation: 96

You have to set badge value in appdelegate's different method like below:

- (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application

Upvotes: 1

chewy
chewy

Reputation: 8267

set your Badge value in this method :-

- (void)applicationDidBecomeActive:(UIApplication *)application 

                       **OR** 

- (void)applicationWillEnterForeground:(UIApplication *)application

Upvotes: 1

Related Questions