Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS, decrease icon badge number

Tags:

ios

icons

badge

I use

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber -1];

to decrement the icon badge count, but actually it gets cleared. when I press the home button, the badge count is not there.

BUT, if I try a fixed value like this

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:4];

, the badge count is there as expected.

So, the question is: Why is

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber -1];

not working?

like image 474
a fair player Avatar asked Nov 13 '22 10:11

a fair player


1 Answers

Why you don't just:

NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber
numberOfBadges -=1;

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];
like image 133
Rui Peres Avatar answered Nov 15 '22 05:11

Rui Peres