iphonecalendarekeventstore

iPhone - How to import all calendar events including event id?


I am developing one simple application related to iPhone calendar. I am able to add the calendar event to from my application to iPhone calendar. As soon as I save event I need to get the saved event ID . How can i achieve this. Below is the code for saving an event.

EKEventStore *eventStore = [[EKEventStore alloc] init]; 
EKEvent *event  = [EKEvent eventWithEventStore:eventStore]; 
event.title     = @"xxx"; 
event.notes = @"yyy";   
event.startDate = [[NSDate alloc] init];
event.endDate   = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate]; 
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];    

Thanks in advance.


Solution

  • For Saving the event call this method , and print all save event with identifiers...

    - (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];
    }
     **NSLog(@"thisEvent.id = %@", thisEvent.eventIdentifier);**
    [controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
    [self.tableView reloadData];
    break;
    
    default:
    break;
    }
    // Dismiss the modal view controller
    [controller dismissModalViewControllerAnimated:YES];
    
    }