the Reverend
the Reverend

Reputation: 12549

How to properly identify an ical event

In iOS the EKEvent class has 2 properties regarding event identifiers: eventIdentifier and the uuid property. When looking at the same synced event on ical on a mac, the CalEvent has a uid property, but None of these match in my tests.

Someone knows how to properly identify an event on both sides?

Upvotes: 2

Views: 865

Answers (2)

Peter Todd
Peter Todd

Reputation: 8651

If you are using iOS 6 try calendarItemExternalIdentifier.

This identifier allows you to access the same event or reminder across multiple devices.

I had this problem using core data, iCloud and calendars. I captured the eventIdentifier and saved it to core data on one device BUT when I checked the other device the eventIdentifier had changed on the calendar.
Resolved it by capturing the calendarItemExternalIdentifier instead of the eventIdentifier: iOS Reference

Capture the calendarItemExternalIdentifier when saving the event:

- (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:
            {[self.selectedClientSession setEventIdentifier:[thisEvent calendarItemExternalIdentifier]];
            .......

When displaying event in the app, query if an event is one of our "session" events :

// Get the event e.g. from a tableview listing of events today    
   calendarEvent = (EKEvent*)[eventsList2 objectAtIndex:indexPath.row];
// Is this one of our session events? Build a predicate to query our clientSession objects by comparing the identifier we captured with the Event calendarItemExternalIdentifier
   self.sessionPredicate = [NSPredicate predicateWithFormat:@" eventIdentifier = %@ ",[calendarEvent calendarItemExternalIdentifier]
// Get the results
   [self setupFetchedResultsController];
//Check that calendarItemExternalIdentifier has been recorded in our session database  
   NSArray *sessionSet = [self.fetchedResultsController fetchedObjects];
//If no results then this is not a client session
   if (sessionSet.count == 0){
    // Just a regular event to display
   } else{
   //It is a client session - display and allow to do interesting stuff
   }

Upvotes: 2

Rob
Rob

Reputation: 437582

It would appear that the latter half of the EKEvent property eventIdentifier contains the CalEvent property uid. I don't know what the first identifier (before the colon) in the eventIdentifier is. It seems to relate to the calendar, but I don't recognize the identifier.

Upvotes: 0

Related Questions