gpt4 book ai didi

ios - 当我设置过去的日期通知时,UILocal 通知不会按计划日期和时间触发

转载 作者:行者123 更新时间:2023-11-28 22:17:01 24 4
gpt4 key购买 nike

我正在使用 UILocalNotification。我的应用程序将为用户提供便利,以便在我的应用程序中设置任何 session 和药物的提醒。

我能够根据我的日程安排日期安排 UINotification。而且当用户将安排过去的日期通知时,我的第二个日程安排通知不会被触发。秒后其他人开火完美但秒不开火。

以下是我的通知流程:

  1. 我正在创建 3 个 session 时间表,其中一个时间已经超过我当前的时间,例如2014-01-28 18:00。而我当前的设备时间是2014-01-28 19:00。现在我正在创建另一个时间表,它的时间是 2014-01-28 19:10。另一个计划日期和时间是 2014-01-28 19:20。

  2. 根据上面的时间表日期时间引用,我的第一个过去日期的通知在时间表创建后被触发。

  3. 当我当前的设备时间来到2014-01-28 19:10。我正在等待通知。但它不会着火。

  4. 在 2014-01-28 19:20,我的第 3 条通知会定期触发。当我将过去的日期添加为日程表时,每次都会发生这种情况。

以下是我用来安排通知的安排通知代码:

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = alertText;
localNotification.alertAction = alertAction;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertLaunchImage = launchImage;
localNotification.applicationIconBadgeNumber = 1;
localNotification.userInfo = userInfo;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];

以下是我的 idReceiveLocalNotification: 处理通知的方法:

if([UIApplication sharedApplication].applicationIconBadgeNumber == 0) {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
}else{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

另外,当我收到通知时,我会调用 MkLocalNotificationScheduler 类来显示警报,代码如下:

 UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Reminder"
message:[thisNotification alertBody]
delegate:self
cancelButtonTitle:@"NO"
otherButtonTitles:@"YES",nil] autorelease];
alert.tag = 1;
[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

请帮助我如何处理所有已过日期或尚未到来的日程安排通知。

最佳答案

不要为过去的时间创建 UILocalNotification。您看到的行为是典型的 UILocalNotification。它立即触发过去的事件。因此,在您的代码中检查时间是否已过,如果已过,则不要创建 UILocalNotification。 (创建过去时间的通知也是毫无意义的)

只为当前时间的 future 时间创建新的 UILocalNotification。

关于ios - 当我设置过去的日期通知时,UILocal 通知不会按计划日期和时间触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21406602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com