Possible reason for badge count is not updating because it is not able to identify value as an int
or NSInteger
.
The badge will not update when some one try to pass non integer value. How ever it will not show any warning or crash in that case, but it just disappear when it can not able to identify required type for badge value.
Looking to your push notification pay load may be the value is not in terms of required type. I mean it may be a string
or boolean
, which is incompatible with badge required type.
So what you can do is, cast it to int
before updating badge count.
Assuming that you have parse payload data to dictionary and result dictionary will be like below code:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Assuming payload data is parse and result in a dictionary like below:
NSDictionary *payloadData = @{ @"alert": @"Test", @"badge": @1, @"sound":@"default" };
NSString *badgeString = [payloadData objectForKey:@"badge"];
NSInteger badgeValue = [badgeString integerValue];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];
}