繁体   English   中英

iOS - 删除重复的EKEvent,事件再次出现

[英]iOS - Delete Recurring EKEvent, event appears again

我在日历中有一个重复发生的事件。 我使用此代码删除单个事件[store removeEvent:event span:EKSpanThisEvent commit:YES error:&errorThis]; 并且此方法返回true但不会从日历中删除该事件。

在使用属性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”参数即可。

编辑:现在只删除匹配的重复事件,而不是一切。

请确保您的应用中只有一个单独模式的EKEventStore实例:

static EKEventStore *eventStore = nil;
+ (EKEventStore *)getEventStoreInstance
{
    if (eventStore == nil){
        @synchronized(self){
            if (eventStore == nil){
                eventStore = [[EKEventStore alloc] init];
            }
        }
    }
    return(eventStore);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM