I know there are a few questions here and there regarding how to delete a local notification which might be all or a particular notification. I have also gone through the local notification class reference and found some methods like repeat time interval,fire date,alert body,time zone etc...but I am unable to find out some sort of information regarding how to modify the fire date that is already been set. Say if the user sets a notification with date today and time 4:50 PM, but if the user wishes to modify the set date/time, what's happening is the notification is firing on both occasions. Which is a blunder as far as programming ethics are concerned!
Actually what I want is the previous notification must be cancelled i.e. date must be modified to edited one and notification should be set and fired on the new date.
This is how I set the notification,sample code:
- (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];
}
}
How to deal with this task?