1

我有一个简单的问题。

首先,我将从发布代码开始:

-(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”而循环的吗?

我怎样才能让这些显示出来?通知正在指定时间显示,但徽章图标未更改...

谢谢!

-亨利

4

1 回答 1

3

你应该改变你的代码顺序:</p>

localNotification.applicationIconBadgeNumber = 1;

localNotification.soundName = UILocalNotificationDefaultSoundName;

取之前的代码:

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

同样的逻辑在 iOS 5.1 对我有用,但代码顺序。在通知应用到系统后,您重置了 badgeNumber 和 soundName。NotificationCenter 需要本地通知对象包含的信息,而不是对象本身,因此,在那个时候,NotificationCenter 无法获取 soundName 或 badgeNumber。很高兴有帮助:-)

于 2013-03-06T02:26:23.480 回答