calendarItemExternalIdentifier is modified after calendar sync? Need help

Hi, I'm facing an issue where I try to store the calendarItemExternalIdentifier in order to retrieve an EKEvent for later use.

the problem is the following.


When using a local calendar, the identifier never changes, so I can retrieve the EKEvent quite easily.

However, when using a EKCalendarTypeExchange calendar, I firstly get an id after saving, and once the calendar app is syncyng, the event has a new calendarItemExternalIdentifier.


Could someone could try to help me figuring out if a reliable method exist in uniquely identifying an Event in the calendar?

Replies

Hi,


I use the property eventIdentifier of EKEvent. But as this ID may change as well I've a method in a calendar helper class which first tries to find an EKEvent by using eventWithIdentifier. If this fails it searches an entry with the same start and end date, hoping this has not been changed:


        EKEventSearchCallback searchBlock = ^(EKEvent *event, BOOL *stop)
        {
            if (([[event startDate] compare:startDate] == NSOrderedSame) &&
                ([[event endDate] compare:endDate] == NSOrderedSame) &&
                ([[event description] containsString:subject]))
            {
                theEvent = event;
                *stop = YES;
            }
        };

        predicate = [[EKEventStore sharedEventStore] predicateForEventsWithStartDate:startDate
                                                                             endDate:endDate
                                                                           calendars:nil];
        [eventStore enumerateEventsMatchingPredicate:predicate usingBlock:searchBlock];


If an event is found this way, I consider it to be the one I was looking for and update the saved eventIdentifier with the one of the found event.


Dirk

I've ran some tests in iOS 9 for iCloud, Google and Exchange. Strange enough, the `calendarItemExternalIdentifier` no longer changed.

I've ran the tests both offline and online, the events synced to the external calendars, yet the identifier did not change in any of the tests. I've logged the identifiers right after making the save, as well as later (after events showed up in Outlook for instance) by looping through EventKit events.


Anyone knows if this was fixed/updated somehow in iOS 9, or am I missing something?

In case it has been fixed/updated, any clues on how reliable it is? We have a live app for which I've set it to log the situations when `calendarItemExternalIdentifier` gets modified (using a similar sollution to what @Dirk described), and it keeps logging those events in iOS 9, so I'm not sure what to make of it.


EDIT: The `calendarItemExternalIdentifier` still changes in some situations. Strange though, since the tests I ran still showed the original identifiers. Might have been cached somewhere.