简体   繁体   中英

Overwrite Local Notifications

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 = UILocalNotificationDefaultSoundName;

[[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 .

使localNotif成为包含此方法的类的属性或实例变量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM