开发者

didReceiveRemoteNotification and Badge Number

Alright im a bit stuck on how to work this.

First ill show you the code.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSString *badge = [apsInfo objectForKey:@"badge"];
    NSLog(@"Received Push Badge: %@", badge);
    application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
}

sorry for the abundance of mess, the Code button was not working.

Now my push gateway provides a number each time for how many alerts are being sent, etc, but if there are previous alerts, how would 开发者_Go百科i get this code to just add +1 to the list instead of just setting the new number


APNS doesn't support increment operations for badges; each push notification generated should be setting what the current value should be. (Mainly due to the fact that push notifications aren't guaranteed to be received by a device)

So, you'll need to have a service/server somewhere keeping track of what badges should be for each of your users, unfortunately.


You should try this:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSString *badge = [apsInfo objectForKey:@"badge"];
    NSLog(@"Received Push Badge: %@", badge);
    int currentBadgeNumber = application.applicationIconBadgeNumber;
    currentBadgeNumber += [[apsInfo objectForKey:@"badge"] integerValue];
    application.applicationIconBadgeNumber = currentBadgeNumber;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜