我在日历中有一个重复发生的事件。我正在使用此代码删除单个事件从日历中删除。
最佳答案
在使用属性 calendarItemExternalIdentifier 的 EKCalendarItem 类引用中,您可以找到它
Recurring event identifiers are the same for all occurrences. If you wish to differentiate between occurrences, you may want to use the start date
所以你只想删除重复你必须做这样的事情:
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendars];
NSArray *theEvents = [eventStore eventsMatchingPredicate:predicate];
NSString *recurrenceEventIdentifier;
for(EKEvent * theEvent in theEvents)
{
if([theEvent.eventIdentifier isEqualToString: recurrenceEventIdentifier]
&& ![eventStore removeEvent:theEvent span:EKSpanThisEvent error:&error])
{
NSLog(@"Error in removing event: %@",error);
}
}
相反,您的方法只删除第一次出现的情况。如果您想删除所有重复发生的事件,只需更改 EKSpanFutureEvents 中的“span”参数即可。
编辑:现在只删除匹配的重复事件,而不是所有内容。
关于iOS - 删除 Recurring EKEvent,事件再次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20520603/