I have built a test-application for local notifications. it looks like this
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
localNotification.alertBody = @"My Next Custom Notification";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:15];
localNotification.alertBody = @"Second One Now";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
NSLog(@"Notifications: %@", [[UIApplication sharedApplication] scheduledLocalNotifications]);
My AppDelegate:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(@"%s", __PRETTY_FUNCTION__);
}
It works fine when I'm in Background or in the LockScreen I'm getting these notifications.
But when the first notifications comes in, it does not show the badge which should be "1" now. When the Second notification comes in the the badge shows "1" and not "2"(which would be the right number now). So what is wrong with my code?