Deleting an EKEvent from device's calendar usi

2019-04-15 01:50发布

I am creating EKEvent, saving it and saving its identifier as well. I wanna access this identifier and delete the specific Event. I am able to retrieve the proper Identifier from database. However, the Event isn't getting deleted from my Device's calendar. My code to delete the event : `NSError* err;

    EKEvent *myEvent = [EKEvent eventWithEventStore:homeobj.eventDB];

    myEvent = [homeobj.eventDB eventWithIdentifier:[dbObj selectEventIdentifier:mypass]];

    [homeobj.eventDB removeEvent:myEvent span:EKSpanThisEvent commit:YES error:&err];

`

1条回答
我命由我不由天
2楼-- · 2019-04-15 02:07

For deleting use this code

-(void)removeMeWithIndex:(int)index
{
    EKEvent* eventToRemove = [eventStore eventWithIdentifier:[arrayofEventId objectAtIndex:index]];

    if (eventToRemove != nil) {
        NSError* error = nil;
        [eventStore removeEvent:eventToRemove span:EKSpanThisEvent error:&error];
    }
}

-(IBAction)remove
{
  [self removeMeWithIndex:0];
}

I have updated my code to check if id exists or not as

-(void)removeMeWithIndex:(int)index
{
    NSLog(@"id is %@",[[NSUserDefaults standardUserDefaults] valueForKey:@"id"]);
    EKEvent* eventToRemove = [eventStore eventWithIdentifier:[[NSUserDefaults standardUserDefaults] valueForKey:@"id"]];

    if (eventToRemove != nil) {
        NSError* error = nil;
        [eventStore removeEvent:eventToRemove span:EKSpanThisEvent error:&error];
    }
}

output after deletion is ...

2013-06-26 18:51:43.999 CARL[674:907] id is 7AFE7AC2-111A-446F-86E6-8D69AD38F1AF:CA946E83-BE08-44AB-8834-06E1E4BFF7E8

your id is something like this ?

After creation of event check in calendar app in device.

enter image description here

After deleting event completion screenshot is :--

enter image description here

Here you can get sample project.

查看更多
登录 后发表回答