I am having some difficulties setting the icon badge with a schedule local notification for my ios application.
I am able to trigger a local notification pop up after 10 seconds when I click the home screen after loading the application. However, the application icon badge number is not getting set. I am using the following code.
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) return;
NSDate *fireTime = [[NSDate date] addTimeInterval:10]; // adds 10 secs
localNotif.fireDate = fireTime;
localNotif.alertBody = @"New Message!";
localNotif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
I don't understand why the local notification pops up but the applicationIconBadgeNumber doesn't get set. I am able to set the icon badge number manually by executing the following code instead.
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
Are you debugging in the Simulator? Same problem on simulator but your code works fine on my iPhone.
are you registering your application for all the badge notification type?
[[UIApplication sharedApplication]registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge];
also, check your notifications settings have not disabled badges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With