I have a method that activates a local notification.
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = [mainTitle text];
// Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotifi开发者_如何学GocationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
The problem is that if you call several times the method, do not overwrite the localNotif, but it adds another. How do I delete the old every time?
Thanks!
Save the local notification object (say in an ivar), and do:
[[UIApplication sharedApplication] cancelLocalNotification:previousNotification];
You can also clear all local notifications with cancelAllLocalNotifications
.
Make localNotif
a property or instance variable of the class that contains this method.
精彩评论