我有一个关于UILocalNotification的问题。
我正在使用我的方法安排通知。
- (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];
}
它能够正常工作,我可以正确地接收通知。问题在于我应该如何取消通知。我正在使用这个方法。
- (void) deleteNewNoteLocalReminder:(NSString*) reminderID noteIDe:(NSInteger)noteIDE
{
[[UIApplication sharedApplication] cancelLocalNotification:(UILocalNotification *)notification ????
}
我不确定该怎么做,但我的问题是:
如何知道应删除哪个 UILocalNotification 对象?
有没有一种方法可以列出所有通知?
我唯一拥有的是我应该删除哪个提醒的 ID。
我正在考虑将 UILocalNotification 对象保存在我的“Note”对象中,并通过这种方式获取它,当我保存到我的 SQLite 数据库时序列化对象等... 是否有更聪明的方法?
CoreData
,我发现使用唯一的托管对象ID非常有帮助:NSManagedObjectID *moID = [managedObject objectID];
。因为在保存后CoreData
才会分配一个永久ID,所以你可以使用:BOOL isTemporary = [[managedObject objectID] isTemporaryID];
- d.ennis