user3815344 user3815344 - 8 months ago 56
iOS Question

Application badge number is not incrementing with local notification

I have been working with local notifications. But the problem is the application icon badge number is not incrementing with local notifcations fired. I tried .applicationIconBadgeNumber+1;
But it's not giving any effect. The application icon badge number is always 1.

enter code here
- (IBAction)save:(id)sender
NSDate *;
UIApplication *app=[UIApplication sharedApplication];
notifyalarm=[[UILocalNotification alloc]init];
if (notifyalarm)
notifyalarm.timeZone=[NSTimeZone defaultTimeZone];
notifyalarm.applicationIconBadgeNumber=[UIApplication sharedApplication] .applicationIconBadgeNumber+1;

[app scheduleLocalNotification:notifyalarm];





After seeing your code I would suggest to use following before setting badge value

NSUserDefaults* userDefs = [NSUserDefaults standardUserDefaults];
//old val
NSInteger iconBadge = [userDefs integerForKey:@"myBadgeVal"];
//updatge val
[userDefs setInteger:iconBadge forKey:@"myBadgeVal"];
[userDefs synchronize];
//set as icon badge

However I'm not sure when 'save' method is called. Make sure this method is called as many times as you expect.

You have to handle locally this number, as [UIApplication sharedApplication] .applicationIconBadgeNumber will always be 0(as you do not update this value anywhere). You could use NSUserDefaults if you wish. Also please provide some code so we can be more helpful.