views:

305

answers:

2

Hello,

I'm trying to remove events that i have created from the iPhone calendar.

I tried this, but it always returns NO:

  [eventStore removeEvent:event span:EKSpanThisEvent error:&err];

I created the event as follows and it works:

eventStore = [[EKEventStore alloc] init];

event = [EKEvent eventWithEventStore:eventStore];

event.title = @"EVENT TITLE";
NSDateFormatter *   dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd:HH:mm"];


NSDate * date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:@"2010-8-15:12:30"];
[date retain];

event.startDate = date;
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];

[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 

Is there a way to remove this event? Or it would be be better that if I try to write this event again it only modifies it instead of creating a new one.

Thanks,

A: 

will you Please send me the code so i can also delete event from Calendar

STUPID PROGRAMMER
A: 

After creating the event I save the eventIdentifier in an array:

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

To delete the events:

EKEventStore* store = [[[EKEventStore alloc] init] autorelease];
   EKEvent* event2 = [store eventWithIdentifier:[arrayofCalIDs objectAtIndex:i]];
if (event2 != nil) {  
  NSError* error = nil;
  [store removeEvent:event2 span:EKSpanThisEvent error:&error];
} 
[myPath release];
iBasel