我在日历中有一个经常性事件。我正在使用此代码删除一个事件[store removeEvent:event span:EKSpanThisEvent commit:YES error:&errorThis];
,并且此方法返回true
,但该事件并未从日历中删除。
问问题
1956 次
2 回答
7
在使用属性 calendarItemExternalIdentifier 的 EKCalendarItem 类参考中,您会发现这个
重复事件标识符对于所有事件都是相同的。如果您希望区分事件,您可能需要使用开始日期
因此,您只想删除重复,您必须执行以下操作:
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”参数。
编辑:现在只删除匹配的重复事件,而不是所有内容。
于 2013-12-18T10:41:48.453 回答
1
请确保您的应用中只有一个单例模式的 EKEventStore 实例:
static EKEventStore *eventStore = nil;
+ (EKEventStore *)getEventStoreInstance
{
if (eventStore == nil){
@synchronized(self){
if (eventStore == nil){
eventStore = [[EKEventStore alloc] init];
}
}
}
return(eventStore);
}
于 2013-12-11T14:50:27.640 回答