问题
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