1

In my app I have objects that trigger Local Notifications.

When the app is in the background the Local Notifications are fired when it's their time to be fired, and that works fine.

For some reason, the Badge Number is not updated.

When setting the Notification object, I use the following code:

UILocalNotification* localNotification = [[UILocalNotification alloc] init];

localNotification.fireDate = obj.noteMeDate; //obj is an object for which the notification is created...
localNotification.alertBody = [NSString stringWithFormat:@"Note: %@", obj.title];
localNotification.alertAction = @"Show Me";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; //this is NOT WORKING...

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

Anyone?

Ohad Regev
  • 5,641
  • 12
  • 60
  • 84

2 Answers2

0

You can't increase the badge number, you can only set it to a certain number. At the time you're scheduling the notification, applicationIconBadgeNumber is 0 (since you're running the application in the foreground), thus every notification is showing only 1 in the badge.

Alexander
  • 8,117
  • 1
  • 35
  • 46
  • Is there a way to react to any event while the app is in the background? I mean, it seems like it still 'active' somewhere. Isn't there a way to instruct the app to react to the notifications? – Ohad Regev Oct 15 '13 at 09:52
  • try with the background task API. – Daij-Djan Oct 15 '13 at 10:04
0

Technically you cannot increment the badge icon directly but there is a way.

int num = [UIApplication sharedApplication].applicationIconBadgeNumber;

[UIApplication sharedApplication].applicationIconBadgeNumber = num + 1;
Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
Selino
  • 111
  • 3
  • 12