我尝试制作一个应用程序,必须在一整天内通知4个传送通知这是我的代码,当我运行代码工作但问题是如果日期已经通过例如2014-03-12 01 :12通知不应该出现,但是当应用关闭时它会出现,我也会尝试使用这些通知[[UIApplication sharedApplication] cancelAllLocalNotifications];
或[[UIApplication sharedApplication] cancelLocalNotifications];
。
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm"];
NSDate *myDate = [df dateFromString:@"2014-03-10 01:04"];
NSDate *myDate1 = [df dateFromString:@"2014-03-10 01:21"];
NSDate *myDate2 = [df dateFromString:@"2014-03-10 01:22"];
UILocalNotification* n1 = [[UILocalNotification alloc] init];
n1.fireDate = myDate;
n1.alertBody = @"one";
[[UIApplication sharedApplication] scheduleLocalNotification: n1];
UILocalNotification* n2 = [[UILocalNotification alloc] init];
n2.fireDate = myDate1;
n2.alertBody = @"uuu";
[[UIApplication sharedApplication] scheduleLocalNotification: n2];
UILocalNotification* n3 = [[UILocalNotification alloc] init];
n3.fireDate = myDate2;
n3.alertBody = @"ontt";
[[UIApplication sharedApplication] scheduleLocalNotification: n3];