取消 UILocalNotification [英] Cancel UILocalNotification
问题描述
我的 UILocalNotification 有问题.
I have a problem with my UILocalNotification.
我正在使用我的方法安排通知.
I am scheduling the notification with my method.
- (void) sendNewNoteLocalReminder:(NSDate *)date alrt:(NSString *)title
{
// some code ...
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.alertBody = title;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:stringID forKey:@"id"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
}
它工作正常,我正确地收到了通知.问题是我什么时候应该取消通知.我正在使用这种方法.
Its work fine and I'm correctly receiving the notification. The problem is when I should cancel the notification. Im using this method.
- (void) deleteNewNoteLocalReminder:(NSString*) reminderID noteIDe:(NSInteger)noteIDE
{
[[UIApplication sharedApplication] cancelLocalNotification:(UILocalNotification *)notification ????
}
我不知道在这里做什么,但我的问题是:
Im not sure what to do here, but my questions are:
我怎么知道我应该删除哪个 UILocalNotification 对象?
有没有办法列出所有通知?
How do I know which UILocalNotification object I should delete?
Is there a way to list all notifications?
我唯一拥有的是我应该删除哪个提醒的 ID.
我正在考虑将 UILocalNotification 对象保存在我的Note"对象中并以这种方式获取它,当我保存到我的 SQLite 数据库时序列化对象等等......有没有更聪明的方法?
The only thing I have is the ID of which reminder I should delete.
I was thinking about to save the UILocalNotification object in my "Note" object and get it that way, and when I saving to my SQLite database serialize the object and so on ... is there a smarter way?
推荐答案
Swift 5:
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: arrayContainingIdentifiers)
这篇关于取消 UILocalNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!