iosobjective-cekeventekeventkitekeventstore

iOS - Delete Recurring EKEvent, event appears again


I have a recurring event in calendar. I'm delete a single event using this code [store removeEvent:event span:EKSpanThisEvent commit:YES error:&errorThis]; and this methods returns true but the event is not deleted from the calendar.


Solution

  • On EKCalendarItem Class reference using the property calendarItemExternalIdentifier you find this

    Recurring event identifiers are the same for all occurrences. If you wish to differentiate between occurrences, you may want to use the start date

    So you want delete only a recurrence you have to 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);
        }
    
    }
    

    Your method instead, deletes only the first occurrence. If you want delete all recurring events just change "span" parameter in EKSpanFutureEvents.

    EDIT: Now only deletes the matching recurrent event, not everything.