user3815344 user3815344 - 2 years ago 107
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
{
eventitem=textfield.text;
NSDate *newdate=self.datepick.date;
UIApplication *app=[UIApplication sharedApplication];
notifyalarm=[[UILocalNotification alloc]init];
if (notifyalarm)
{
notifyalarm.fireDate=newdate;
notifyalarm.timeZone=[NSTimeZone defaultTimeZone];
notifyalarm.alertBody=eventitem;
notifyalarm.applicationIconBadgeNumber=[UIApplication sharedApplication] .applicationIconBadgeNumber+1;

[app scheduleLocalNotification:notifyalarm];

}


}

Answer Source

UPDATE

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
iconBadge++;
//store
[userDefs setInteger:iconBadge forKey:@"myBadgeVal"];
[userDefs synchronize];
//set as icon badge
notifyalarm.applicationIconBadgeNumber=iconBadge;

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download