【发布时间】:2013-07-29 18:00:46
【问题描述】:
我正在安排一组 UILocalNotifications。他们准时开火,似乎工作正常。但是,有时,当触发 NEW 通知时,会同时触发多个(有时只有一个)OLD 通知。
例如,我安排 UILocalNotification 在星期一下午 5 点取出垃圾,没有重复间隔。它开火没有问题,而且准时。周二,我有一个 UILocalNotification 可以在周二下午 5 点将垃圾箱带入,同样没有重复间隔。当那个触发时,我会看到 NOW 的正确通知,但在当前通知下方还会显示另一个通知,用于 1 天前。我没有重新安排此通知。好像是昨天的通知。
这很奇怪,我无法在任何一致的基础上重现它。我认为可能以某种方式添加了一些旧通知,所以我添加了一些逻辑来运行所有计划的通知并删除任何具有过去的触发日期但没有帮助的通知。其他人见过这个问题吗?是否有一些手动清除我需要在触发时执行的通知?
编辑:添加了一些调度代码
//only schedule if the alert date is later than now
if ([AMDateUtil isNowEarlierThanDate:alertDate]) {
//create the notification and setup some properties
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = alertDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertAction = nil;
localNotification.soundName = UILocalNotificationDefaultSoundName;
//add the local notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
【问题讨论】:
-
请显示您如何创建本地通知的代码。源码可以提供线索。
-
@BlackFrog 添加了代码
标签: ios objective-c uilocalnotification