0
votes

I'm having trouble updating the badge count on an iOS7 application from a push notification. It works fine in iOS8 but, although the push is being received, the badge count isn't updating in iOS7.

A test payload I'm using is as follows: {"aps":{"alert":"Test","badge":1,"sound":"default"}}

Any ideas what could be going on?

Setting the badge count manually within the app works fine, it's just the push count being ignored.

1
try changing 1 to @(1) or to @"Increment"Josh Gafni

1 Answers

1
votes

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];
}