Reputation:
For some reason Badge Numbers are not being incremented in my app
I tried
[UIApplication sharedApplication].applicationIconBadgeNumber =
[UIApplication sharedApplication].applicationIconBadgeNumber + 1;
and also:
[UIApplication sharedApplication].applicationIconBadgeNumber =
[UIApplication sharedApplication].applicationIconBadgeNumber +
[[[userInfo objectForKey:@"aps"] objectForKey: @"badge"] intValue];
Full Code:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[UIApplication sharedApplication].applicationIconBadgeNumber =
[UIApplication sharedApplication].applicationIconBadgeNumber + 1;
}
It always displays 1, from my server I send the playload with badges = 1
Upvotes: 0
Views: 480
Reputation: 45500
The problem is didReceiveRemoteNotification
does not get called when your app is not active. Therefore you can only increase it once the application becomes active.
You will need to track the bagde count in your database and send it along with the push notification.
Now your app will be responsible for decreasing/increasing that count and finally update that badge count field into your table so that on the next push alerts your server knows what badge number the app icon should display.
Upvotes: 0
Reputation: 311
You should keep track of badge counters on the server.
When your app become active, set the badge count to 0 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
and send a request to a custom API of your server that's telling that the badge count is 0 now
Upvotes: 1