Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set applicationIconBadgeNumber with scheduleLocalNotification?

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;
like image 313
user1157352 Avatar asked Jan 18 '12 23:01

user1157352


2 Answers

Are you debugging in the Simulator? Same problem on simulator but your code works fine on my iPhone.

like image 90
Linghua Zhang Avatar answered Oct 14 '22 08:10

Linghua Zhang


are you registering your application for all the badge notification type?

[[UIApplication sharedApplication]registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge]; 

also, check your notifications settings have not disabled badges.

like image 42
Nik Burns Avatar answered Oct 14 '22 08:10

Nik Burns