Are you really saving UILocalNotification or are you using it as a transient property?
, UILocalNotification userInfo . / . :
notificationID userInfo notificationID Core Data . , int NSString ( ).
UILocalNotification, Entity, :
- (void)createNotification
{
static NSUInteger kDeadlineWarningPeriod = 3600;
UILocalNotification *notification = [[UILocalNotification alloc] init];
…
self.notificationID = @"some generated ID";
[notification.userInfo setValue:self.notificationID forKey:@"notificationID"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
}
- (void)cancelNotification
{
[[[UIApplication sharedApplication] scheduledLocalNotifications] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UILocalNotification *notification = (UILocalNotification *)obj;
NSDictionary *userInfo = notification.userInfo;
NSString *notificationID = [userInfo valueForKey:@"notificationID"];
if ([notificationID isEqualToString:self.notificationID])
{
[[UIApplication sharedApplication] cancelLocalNotification:notification];
*stop = YES;
self.notificationID = nil;
}
}];
}
, , .
, .
UPDATE
, , Entity ( , BOOL), :
@property (nonatomic, assign) BOOL reminder;
- (void)setReminder:(BOOL)reminder {
[self willAccessValueForKey@"reminder"];
BOOL hasReminder = [[self primitiveValueForKey:@"reminder"] booleanValue];
[self didAccessValueForKey:@"reminder"];
if (hasReminder && !reminder) {
[self cancelNotification];
}
else if (!hasReminder && reminder) {
[self createNotification];
}
if (reminder != hasReminder)
{
[self willChangeValueForKey:@"reminder"];
[self setPrimitiveValue:[NSNumber numberWithBool:reminder] forKey@"reminder"];
[self didChangeValueForKey:@"reminder"];
}
}
"" , , notificationID nil . .
, - .
, , 64 , . , , .