iOS - 如何创建包含排除事件(日期)的定期日历事件?

时间:2018-03-17 14:15:09

标签: ios objective-c events recurrence repeat

我正在尝试通过JSON API在日历中创建一个循环事件,但是出现排除事件(/ date)我不知道该怎么做。我想我创建了一个循环事件,然后我删除了出现。

更新: 例如,事件每个周末都会重复。但是,我从时间线中删除了一些周末,为重复规则创建了一个例外。 如何通过API获取这些排除日期?

我的代码:  1.来自api json的CreateEvent:

NSDictionary *dicEvent = [self.arrayEvents objectAtIndex:index];

EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = [dicEvent objectForKey:@"RecurrenceRule"];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
event.startDate = [dicEvent objectForKey:@"startDate"];
event.endDate =  [dicEvent objectForKey:@"endDate"];
    EKSpan span = EKSpanFutureEvents;

[self.eventStore saveEvent:self.savedEvent span:span commit:YES error:&error];


2. then with exclusion occurrences, I think I delete occurences.
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.occurencesIdentifier isEqualToString: eventoccurencesIdentifier]) {
    // delete occurencesIdentifier
break;
}

请在我出错的地方帮助我。 谢谢!

0 个答案:

没有答案