当我打开通知托盘以查看通知时,UILocalNotification会触发

我使用了本地通知并安排了开火日期,但是当应用程序处于后台时我打开通知托盘查看通知,然后本地通知会自动触发,但是火灾日期仍然存在..是否有任何解决方案可以解决该问题

这听起来像你有两个问题。 首先,创建了本地通知,并在过去设置了开火日期 – 这就是为什么它会在您打开应用程序时立即显示的原因。

其次,您可能将通知的repeatInterval设置为非零值,这将导致它多次出现。

请参阅以下代码,以便在下午3点设置本地通知:

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.alertBody = @"This is a test alert"; NSCalendar *currentCalendar = [NSCalendar currentCalendar]; NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setHour: 15]; [comps setMinute: 0]; [comps setSecond: 0]; NSDate *threePM = [currentCalendar dateFromComponents:comps]; // Test if the current time is after three or not: if(threePM != [threePM earlierDate: [NSDate date]]) { comps = [[NSDateComponents alloc] init]; [comps setDay: 1]; threePM = [currentCalendar dateByAddingComponents: comps toDate: threePM options: 0]; } localNotification.fireDate = threePM; localNotification.repeatInterval = 0; [[UIApplication sharedApplication] scheduleLocalNotification: localNotification];