过去的通知出现在现在

时间:2014-03-08 06:00:25

标签: ios iphone objective-c

我正在尝试制作一个应用程序通知,提醒某些特定日期和时间,但我遇到的问题是当运行过去通知的代码也出现时... 例如;昨天是2014年3月7日在具体时间我设置通知但是今天2014年3月8日在特定时间我设置了不同的通知在这种情况下我运行代码昨天通知也出现所以我需要停止昨天通知请有人帮助解决这个

NSDateFormatter *df = [[NSDateFormatter alloc] init];

[df setDateFormat:@"yyyy-MM-dd HH:mm"];

NSDate *myDate = [df dateFromString:@"2014-03-08 16:35"];
NSDate *myDate1 = [df dateFromString:@"2014-03-08 16:36"];
NSDate *myDate2 = [df dateFromString:@"2014-03-08 16:39"];
NSDate *myDate3 = [df dateFromString:@"2014-03-08 16:40"];

UILocalNotification* n1 = [[UILocalNotification alloc] init];

n1.fireDate = myDate;








n1.alertBody = @"one";



UILocalNotification* n2 = [[UILocalNotification alloc] init];



n2.fireDate=myDate1;
n2.alertBody = @"two";

[[UIApplication sharedApplication] scheduleLocalNotification: n1];

[[UIApplication sharedApplication] scheduleLocalNotification: n2];



UILocalNotification* n3 = [[UILocalNotification alloc] init];

n3.fireDate = myDate2;









n3.alertBody = @"one";



UILocalNotification* n4 = [[UILocalNotification alloc] init];


n4.fireDate=myDate3;
n4.alertBody = @"two";

[[UIApplication sharedApplication] scheduleLocalNotification: n3];

[[UIApplication sharedApplication] scheduleLocalNotification: n4];

1 个答案:

答案 0 :(得分:0)

使用

  [[UIApplication sharedApplication] cancelAllLocalNotifications];

然后重新安排新的。