Here is what I'd like to do...
The user should be able to schedule a local notification via the following action sheet:
Tapping the first button will fire the notification 15 minutes prior to a given date and time. When the user returns to the action sheet and taps the second option, which will fire the notification 30 minutes prior to a given date and time, I'd like to cancel the old notification and and schedule the new one instead. Finally the third button should cancel any notification scheduled from this action sheet.
This is the interesting part of the code I currently use:
Code:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = alert;
localNotification.fireDate = myNewDate;
localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.soundName = UILocalNotificationDefaultSoundName;//alarm.caf
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
}
else if (buttonIndex == 1) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = alert;
localNotification.fireDate = myNewDate;
localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.soundName = UILocalNotificationDefaultSoundName;//alarm.caf
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
}
else if (buttonIndex == 2) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
}
The above code works almost like I want it. But I use this in six different places within my app, so cancelAllLocalNotifications is not an option. I guess I have to use something like this:
Code:
[[UIApplication sharedApplication] cancelLocalNotification:notification];
Unfortunately I just can't seem to get it to work. The app always fires both notifications.
Does anybody have an idea how to accomplish this? Any help is highly appreciated! Thanks in advance!