简体   繁体   中英

Badge count not updating from push on iOS7

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM