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.
Asked
Active
Viewed 2,031 times
1

CodeBender
- 35,668
- 12
- 125
- 132

Afnan
- 888
- 1
- 13
- 37
2 Answers
7
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.

Akshit Zaveri
- 4,166
- 6
- 30
- 59

Bonch
- 158
- 8
-
3Then you need also distinguish events with the eventIdentifier otherwise you'll delete all events starting and ending with that dates – Bonch Dec 18 '13 at 15:47
-
Let say if I have recurrence for Sun, Mon and I want to delete only Mon recurrences. So This wont help. – Kudos Jan 11 '23 at 13:28
1
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);
}

Mohammad Rabi
- 1,412
- 2
- 21
- 41
-
How does it make difference? I can delete events that are not recurring. – Afnan Dec 12 '13 at 06:10