Search code examples
iphoneiosekeventkitekevent

Deleting an event using Event Kit in iPhone


I am using Event Kit in my iOS application and creating a event using Event Kit. I am able to create it but I want to give the ability to delete also. But I am not able to do that. I know there is a method for EKEventStore to delete event but I am not able to make event object. I have event identifier as a string but I am not able to create an event object using it. Can someone please guide me to do it?

Regards Pankaj


Solution

  • When ever you are creating an event save its id like this:

    NSString* str = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
    

    pass the id to delete the event, here is code

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