The eventIdentifier getting on save is not able to fetch the event using eventIdentifier.
So we are unable to update the EKEvent programmatically even if we have its eventIdentifier
In [SimpleEKDemo][1] provided by Apple
log the eventIdentifier on EKEventEditViewDelegate method
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
NSError *error = nil;
EKEvent *thisEvent = controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;
case EKEventEditViewActionSaved:
// When user hit "Done" button, save the newly created event to the event store,
// and reload table view.
// If the new event is being added to the default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList addObject:thisEvent];
}
[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
NSLog(@"thisEvent.id = %@", thisEvent.eventIdentifier);
[self.tableView reloadData];
break;
case EKEventEditViewActionDeleted:
// When deleting an event, remove the event from the event store,
// and reload table view.
// If deleting an event from the currenly default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList removeObject:thisEvent];
}
[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
[self.tableView reloadData];
break;
default:
break;
}
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];
}
Run the application on device, we will get the eventIDentifier like :
eventidonsave = 3CB60848-6CCA-43BF-B2C6-9EB9F5CFBBB7:C6CDE9DAA864420BA9A2E02CD886369700000000000000000000000000000000
Get the event using event identifier on next run
EKEventStore *eventStore1 = [[EKEventStore alloc] init];
EKEvent *event1 = [eventStore1 eventWithIdentifier: eventidonsave ];
if(event1){
NSLog(@"event1 id = %@", event1.eventIdentifier);
}else{
NSLog(@"Not Found");
}
We will get "Not Found".
log the event ids in the place of fetching events, and run again the app
- (NSArray *)fetchEventsForToday {
....
....
for(EKEvent *eachEvent in events){
NSLog(@"eachEvent.id = %@", eachEvent.eventIdentifier);
}
}
we can see we are getting a different eventIdentifier like 3CB60848-6CCA-43BF-B2C6-9EB9F5CFBBB7:040000008200E00074C5B7101A82E00800000000646C6F747573C3010000000000000000100000000DA068F782418C4880257958003F776C
this is not the same as 'eventidonsave'
Hi all , thanks to reading. It got solved. The above code(not its edited) is working fine. I guess the issue was, the eventid was logged before this line "[controller.eventStore saveEvent:.. "
NO just moved to after save. and seems to be okay.