Question

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.

Was it helpful?

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.

OTHER TIPS

Please make sure you have only one instance of EKEventStore in singleton pattern in your app :

static EKEventStore *eventStore = nil;
+ (EKEventStore *)getEventStoreInstance
{
    if (eventStore == nil){
        @synchronized(self){
            if (eventStore == nil){
                eventStore = [[EKEventStore alloc] init];
            }
        }
    }
    return(eventStore);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top