IOS - Remove recurring EKEvent event reappears

I have a recurring event on the calendar. I delete one event using this code [store removeEvent:event span:EKSpanThisEvent commit:YES error:&errorThis];, and this method returns true, but the event is not removed from the calendar.

+4
source share
2 answers

In the EKCalendarItem Class link using the calendarItemExternalIdentifier property you will find this

Duplicate event identifiers are the same for all occurrences. If you want to distinguish between occurrences, you can use the start date

So you want to remove only the repetition, you should do something like this:

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);
    }

}

. , "span" EKSpanFutureEvents.

EDIT: , .

+7

, , EKEventStore singleton :

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

All Articles