如何连续30天设置UILocalNotification

Sha*_*bal 5 iphone nsdate ios uilocalnotification

我想在每天上午8:00连续30天安排UILocalNotificaion,我想仅使用一个UILocationNotification实例来实现该功能.这是我安排本地通知的代码.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];
NSDate *date = [[NSDate alloc] init];
date = [formatter dateFromString:@"08:00"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.alertBody = @"You just received a local notification";
localNotification.alertAction = @"View Details";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[formatter release];
[date release];
Run Code Online (Sandbox Code Playgroud)

它将在上午08:00永远发出每日通知,但我希望仅连续30天收到通知.最简单的解决方案是启动30个UILocalNotifications,但我希望使用1个UILocalNotification实例执行此操作.我怎样才能做到这一点?请帮忙.

KAR*_*MED 4

创建通知时,在 UILocalNotification userInfo 属性中保存 NSDate 对象。当您打开通知时,请检查当前日期和 userinfo 中的日期。如果差异超过 30 天,您可以取消本地通知。

  • 如果用户检查或收到通知,您的解决方案将起作用。但是如果用户没有收到或检查任何通知怎么办? (2认同)