我有一个大问题!我的问题是,我已经在我的委托中实现了本地通知代码。我已将此代码放入 didEnterBackround 方法中。但是,我为每个 didEnterBackround 获得了一个本地通知。如果最新的通知消失了,是否有可能只启动一个新的通知触发?就像我有一个 5 天后触发的 localnotifi 一样。当我打开和关闭应用程序 5 次并等待 5 天时,我会收到 5 个本地通知。是否有可能让应用程序只创建一个启动,然后出现一个新的启动?!
我的代码:
NSCalendar *calender = [NSCalendar autoupdatingCurrentCalendar];
NSDate *currentDate = [NSDate date];
NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:currentDate];
NSDateComponents *timeComponents = [calender components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:currentDate];
NSDateComponents *temp = [[NSDateComponents alloc]init];
[temp setYear:[dateComponents year]];
[temp setMonth:[dateComponents month]];
[temp setDay:[dateComponents day]];
[temp setHour:[timeComponents hour]];
[temp setMinute:[timeComponents minute]];
[temp setSecond:[timeComponents second] +10];
NSDate *fireTime = [calender dateFromComponents:temp];
UILocalNotification *localN = [[UILocalNotification alloc]init];
localN.fireDate = fireTime;
localN.timeZone = [NSTimeZone defaultTimeZone];
localN.alertBody = @"BLA BLA BLA!";
localN.alertAction = @"GO BACK";
localN.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localN];