开发者

Overwrite Local Notifications

开发者 https://www.devze.com 2023-03-29 05:30 出处:网络
I have a method that activates a local notification. UILocalNotification *localNotif = [[UILocalNotification alloc] init];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消