我知道有一些关于如何删除本地通知的问题,可以在这里和那里找到。我也查看了本地通知类参考,发现了一些方法,如重复时间间隔、触发日期、警报正文、时区等等...但我无法找到关于如何修改已设置的触发日期的信息。比如说,如果用户设置了一个今天下午4:50的通知,但如果用户希望修改设置的日期/时间,那么通知将在两个场合都触发,这是编程伦理方面的错误!
实际上,我想要的是取消之前的通知,即将日期修改为编辑后的日期,并在新日期上设置和触发通知。
以下是我设置通知的样本代码:
如何处理这个任务?
实际上,我想要的是取消之前的通知,即将日期修改为编辑后的日期,并在新日期上设置和触发通知。
以下是我设置通知的样本代码:
- (void)setNotification
{
//Set notification after confirmation of saved data
Class cls = NSClassFromString(@"UILocalNotification");
reminderNotification = [[cls alloc] init];
if (cls != nil)
{
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *notificationDate = [dateFormat dateFromString:textField2.text];
reminderNotification.fireDate = notificationDate;
reminderNotification.timeZone = [NSTimeZone defaultTimeZone];
NSString *reminderText = [NSString stringWithFormat:@"%@ 's %@ on %@",textField.text,textField1.text,strDate];
reminderNotification.alertBody = reminderText;
reminderNotification.alertAction = @"View";
reminderNotification.soundName = @"lazy_afternoon.mp3";
reminderNotification.applicationIconBadgeNumber = 1;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:self.textField1.text forKey:kReminder];
reminderNotification.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNotification];
[reminderNotification release];
}
}
如何处理这个任务?