Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting an event from iPhone's calendar

I am trying to delete an event from the Calendar on user request. This is what I've come up with:

// Deleting Event
    EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
event.title     = appDelegate.title1;
event.startDate = appDelegate.recAddDate;
event.endDate   = appDelegate.currentDateName;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore removeEvent:event span:EKSpanThisEvent error:&err];

Below is the function I'm calling to remove the event from the event array. Items array is used to fetch events from iPhone calendar

- (BOOL)removeEvent:(EKEvent *)event span:(EKSpan)span error:(NSError **)error{
    VoiceRecorderAppDelegate *appDelegate = (VoiceRecorderAppDelegate *)[[UIApplication sharedApplication] delegate];
    [items removeObjectAtIndex:appDelegate.objectindexpath];
}
like image 382
STUPID PROGRAMMER Avatar asked Sep 08 '10 06:09

STUPID PROGRAMMER


People also ask

Why won't an event delete from my iPhone calendar?

Sometimes, the events on your phone's iCloud calendar may fail to sync. This often happens with recurring events imported from Outlook. Turn off iCloud sharing for all your calendars. This should delete all the calendar data and events from your iPhone.

How do I delete a calendar event on my iPhone without sending a cancellation?

select and right-click the calendar on the calendars pane on the left and chose delete. pick the option delete and do not notify.


1 Answers

Firstly, save the eventId for the event while adding/saving events to the calendar.

[eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 
NSString* str = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
[arrayofEventId addObject:str];

and then identify the event you want to remove ande then remove that event.

EKEventStore* store = [[EKEventStore alloc] init];
EKEvent* eventToRemove = [store eventWithIdentifier:[arrayofEventId objectAtIndex:i]];
 if (eventToRemove != nil) {  
   NSError* error = nil;
  [store removeEvent:eventToRemove span:EKSpanThisEvent error:&error];
 } 

Also don't forget to remove that event from arrayofEventId as well.

like image 116
thatguy Avatar answered Oct 13 '22 05:10

thatguy