[英]iOS UILocalNotification - Badge Icon and Notification Sound
我有一个应该相当简单的快速问题。
首先,我将通过发布代码开始:
-(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;
}
似乎显示了localNotification,但是徽章和声音永远不会显示和播放。 可能是因为这是由于“repeatInterval”而循环吗?
我怎样才能显示这些内容? 通知正在指定时间显示,但徽章图标未更改...
谢谢!
-Henry
您应该更改您的代码顺序:
localNotification.applicationIconBadgeNumber = 1;
localNotification.soundName = UILocalNotificationDefaultSoundName;
以前拿代码:
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
在iOS 5.1中,同样的逻辑对我有用,但是代码顺序。 在通知应用于系统后重置badgeNumber和soundName。 NotificationCenter需要本地通知对象包含的信息,而不是对象本身,因此,在那个时候,NotificationCenter无法获取soundName或badgeNumber.Glad有帮助:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.