Remove EKEvent from EKEventStore from iOS Calendar app

I added the event to the default calendar on the iPhone using the following code:

EKEventStore *store=[[EKEventStore alloc] init];
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (!granted) {
            return ;
        }
        EKEvent *event=[EKEvent eventWithEventStore:store];
        event.title=@"This is the event";
        event.startDate=[NSDate date];
        event.endDate =[event.startDate dateByAddingTimeInterval:60*60];
        event.allDay=YES;
        NSURL *url=[NSURL URLWithString:@"http://www.google.com"];
        event.URL=url;
        [event setCalendar:[store defaultCalendarForNewEvents]];
        NSError *errr=nil;
        [store saveEvent:event span:EKSpanThisEvent commit:YES error:&errr]; //        NSLog(@"%@",errr); //        NSLog(@"%@",event.eventIdentifier);

    }];

Now I want to delete this event. The code I tried is as follows:

EKEventStore *store1=[[EKEventStore alloc]init];
            NSPredicate *predicate=[store1 predicateForEventsWithStartDate:[[tableViewScheduleArray objectAtIndex:btn.tag] objectForKey:@"Schedule_Date"] endDate:[[tableViewScheduleArray objectAtIndex:btn.tag] objectForKey:@"Schedule_End_Time"] calendars:nil];
            NSArray *arr=[store eventsMatchingPredicate:predicate];
            dispatch_async(dispatch_get_main_queue(), ^{
                [store1 removeEvent:[arr objectAtIndex:0] span:EKSpanThisEvent commit:YES error:nil];
            });

This did not work, but it also did not result in an error.

I tried a few snippets of code from Stack Overflow, but none of them worked.

+4
source share
1 answer

I got a solution, These were stupid mistakes.

a "store" property that is not declared strong. how i changed it worked.

And working on the code correctly.

0
source

Source: https://habr.com/ru/post/1537626/


All Articles