Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 472
pankaj Avatar asked Dec 21 '25 11:12

pankaj


2 Answers

Refer this as event.eventIdentifier changes value. So you must keep track of the event.title you set to the event and access the event and delete it

NSDate *startDate = <EVENT_START_DATE>;
NSDate *endDate = <EVENT_END_DATE>;

NSPredicate *predicateForEvents = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:[NSArray arrayWithObject:[eventStore defaultCalendarForNewEvents]]];
//set predicate to search for an event of the calendar(you can set the startdate, enddate and check in the calendars other than the default Calendar)

NSArray *events_Array = [eventStore eventsMatchingPredicate: predicateForEvents];                        
//get array of events from the eventStore

for (EKEvent *eventToCheck in events_Array) 
{
    if( [eventToCheck.title isEqualToString: @"yourEventTitle"] ) 
    {
         NSError *err;
         BOOL success = [eventStore removeEvent:eventToCheck span:EKSpanThisEvent error:&err];
         NSLog( @"event deleted success if value = 1 : %d", success );
         break;

    }
}
like image 89
Vimal Venugopalan Avatar answered Dec 23 '25 04:12

Vimal Venugopalan


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];
    } 
like image 32
Sonu Avatar answered Dec 23 '25 03:12

Sonu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!