0
EKEvent가 추가 또는 삭제되었는지 어떻게 알 수 있습니까? 그래서 나는 이벤트에 대한 알림을 예약 할 수 있습니다. 그렇지 않으면 삭제 된 이벤트에 대해서도 알림을 예약합니다. 어떤 도움?이벤트 저장소 변경 사항을 감지하는 방법 및 변경 사항은 무엇입니까? EKEventStoreChangedNotification에서
-(void)storeChanged:(NSNotification*)notification{
EKEventStore *ekEventStore = notification.object;
NSDate *now = [NSDate date];
NSDateComponents *offsetComponents = [NSDateComponents new];
[offsetComponents setDay:0];
[offsetComponents setMonth:4];
[offsetComponents setYear:0];
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:offsetComponents toDate:now options:0];
NSArray *ekEventStoreChangedObjectIDArray = [notification.userInfo objectForKey:@"EKEventStoreChangedObjectIDsUserInfoKey"];
NSPredicate *predicate = [ekEventStore predicateForEventsWithStartDate:now
endDate:endDate
calendars:nil];
// Loop through all events in range
[ekEventStore enumerateEventsMatchingPredicate:predicate usingBlock:^(EKEvent *ekEvent, BOOL *stop) {
// Check this event against each ekObjectID in notification
[ekEventStoreChangedObjectIDArray enumerateObjectsUsingBlock:^(NSString *ekEventStoreChangedObjectID, NSUInteger idx, BOOL *stop) {
NSObject *ekObjectID = [(NSManagedObject *)ekEvent objectID];
if ([ekEventStoreChangedObjectID isEqual:ekObjectID]) {
// Log the event we found and stop (each event should only exist once in store)
NSLog(@"calendarChanged(): Event Changed: title:%@", ekEvent.title);
NSLog(@"%@",ekEvent);
NSInteger total = [[[UIApplication sharedApplication] scheduledLocalNotifications]count];
if (total == 64) {
[self cancelLastNotification];
}
NSArray *newArray = [[NSArray alloc]initWithObjects:ekEvent, nil];
[self scheduleNotificationForCalendarEvents:NO andEvents:newArray];
*stop = YES;
}
}];
}];
}