Reputation:
I have a quick question that should be fairly simple.
First, I am going to start off by posting code:
-(void)notification
{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (!localNotification)
return;
// Current date
NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendar
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; // gets the year, month, day, hour and minutesfor today's date
[components setHour:19];
[components setMinute:30];
[components setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EST"]];
localNotification.fireDate = [calendar dateFromComponents:components];
localNotification.repeatInterval = NSDayCalendarUnit;
[localNotification setAlertBody:@"Your 'Daily Quote' is ready!"];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
localNotification.applicationIconBadgeNumber = 1;
localNotification.soundName = UILocalNotificationDefaultSoundName;
}
It seems that the localNotification is shown, but the Badge and the sound are never displayed and played. Could it be because this is looping due to "repeatInterval"?
How can I get these displayed? The notification is being displayed at the specified time, but the badge icon is not changed...
Thanks!
-Henry
Upvotes: 1
Views: 1409
Reputation: 373
You should change your code order:
localNotification.applicationIconBadgeNumber = 1;
localNotification.soundName = UILocalNotificationDefaultSoundName;
Take the code before:
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
The same logic is work for me at iOS 5.1 , but the code order. You reset the badgeNumber and the soundName after the notification apply to the system. NotificationCenter need the info which the local notification object contains,not the object itself,so,in that time,the NotificationCenter can not get the soundName or badgeNumber.Glad to have helped :-)
Upvotes: 3