2013-10-04 3 views
3

캘린더에 반복 이벤트 (EKEvent)를 작성했습니다. 특정 날짜에 반복되는 이벤트 중 하나를 가져오고 수정하려면 어떻게합니까?미래의 특정 반복 EKEvent를 얻는 방법은 무엇입니까?

이벤트는 다음 코드에 의해 만들어진 :

+ (void) writeTestEvent{ 

    EKEventStore *eventStore = [[EKEventStore alloc] init]; 
    EKEvent *event = [EKEvent eventWithEventStore:eventStore]; 

    event.calendar = [eventStore defaultCalendarForNewEvents]; 
    event.title = @"Hello World!"; 
    event.startDate = [NSDate date]; 
    event.endDate = [NSDate date]; 

    EKRecurrenceRule *recurrenceRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval:1 end:nil]; 
    [event addRecurrenceRule:recurrenceRule]; 

    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
     if (granted) { 
      BOOL isSaved = [eventStore saveEvent:event span:EKSpanFutureEvents commit:YES error:&error]; 
      NSLog(@"isSaved: (%d) with error: %@", isSaved, error); 
     } else { 
      NSLog(@"not granted with error: %@", error); 
     } 
    }]; 
} 

-predicateForEventsWithStartDate:endDate:calendars:이뿐만 아니라 특정 이벤트, 날짜 범위 내에 이벤트를 가져옵니다 사용. 이벤트 식별자를 사용하는 것은 하나의 이벤트 만 가져 오지만 특정 날짜는 가져 오지 않습니다. documentation에 따르면

답변

3

:

반복 이벤트 식별자는 모든 경우에 대해 동일합니다. 발생을 구별하려면 시작 날짜를 사용하는 것이 좋습니다.

샘플은 EKEvent의 특정 재발을 얻을 수 있습니다 :

EventStore *eventStore = [[EKEventStore alloc] init]; 

NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendars]; 

NSArray *results = [eventStore eventsMatchingPredicate:predicate]; 
for (int i = 0; i < results.count; i++) { 
    EKEvent *event = [results objectAtIndex:i] 
    if ([event. eventIdentifier isEqualToString: eventIdentifier]) { 
     // Match!! 
    break; 
    } 
} 
+0

이 매우 불행한 일이다. 그래도 알아 줘서 고마워! –

+0

첫 번째 줄에는 EventStore가 아니라 EKEventStore 여야합니다. –