user3815344
user3815344

Reputation: 243

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];

    }

}

Upvotes: 1

Views: 1119

Answers (2)

Abhishek Sharma
Abhishek Sharma

Reputation: 3283

If your first Settled LocalNotification will fire first then you can use following way to set BadgeCount.

notifyalarm.applicationIconBadgeNumber = ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] + 1);

Upvotes: 0

hris.to
hris.to

Reputation: 6363

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.

Upvotes: 1

Related Questions