我想选择日期用户 UILocalNotification
,但如果用户未点按通知栏以启动应用,则会在10秒后继续推送本地通知。这意味着该应用将推送2本地通知:
我尝试了这段代码,但它不起作用:
UILocalNotification *reminderNote = [[UILocalNotification alloc]init];
reminderNote.fireDate = _selectedDate;
reminderNote.repeatInterval = NSSecondCalendarUnit;
reminderNote.alertBody = @"some text";
reminderNote.alertAction = @"View";
reminderNote.soundName = @"sound.aif";
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
提前致谢。
答案 0 :(得分:1)
这有几个问题:
UILocalNotification
。来自Apple文档:请注意,不支持小于一分钟的间隔。
NSCalendarUnit
间隔重复,例如每小时,每天或每月。有关详细信息,请参阅this post。答案 1 :(得分:0)
我认为您需要为UILocalNotification
创建2个不同的UILocalNotification对象并在不同时间触发
喜欢
-(void) fireAtDate:(NSDate *) date {
UILocalNotification *reminderNote = [[UILocalNotification alloc]init];
reminderNote.fireDate = _selectedDate;
reminderNote.repeatInterval = NSSecondCalendarUnit;
reminderNote.alertBody = @"some text";
reminderNote.alertAction = @"View";
reminderNote.soundName = @"sound.aif";
reminderNote.fireDate = date;
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
}
...
[self fireDate([NSDate dateWithTimeIntervalSinceNow:0])];
[self fireDate([NSDate dateWithTimeIntervalSinceNow:10])];