Deleting an EKEvent from device's calendar using its identifier

拜拜、爱过 提交于 2019-12-21 23:08:20

问题


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:


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.

After deleting event completion screenshot is :--

Here you can get sample project.



来源:https://stackoverflow.com/questions/17316768/deleting-an-ekevent-from-devices-calendar-using-its-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!