Reputation: 325
I want to increase the badge count when a notification is received and decrease when user tap or open the app.
I also try this code but it doesn't work.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
}
Upvotes: 2
Views: 3184
Reputation:
As per my knowledge application is showing number as badge count which is sent by you in this { "aps" : { "badge" : 9 } } dictionary as badge value.
What you are setting in this method
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
}
is set when you open application by tapping on remote notification which is logically not write because when you are opening application that time you are setting badge count.
You must have to pass badge value in your aps dictionary and you may reset badge count when application opened (in didFinishLaunchingwithOption method).
Apart from this, there is no method you can write in your application code that set badge count as soon as you receive push notification and your application is already in kill mode(not open at all).
Upvotes: 1