Reading Apple's docs, I'm still confused as to what the difference is between EKCalenderItem's calendarItemExternalIdentifier and EKEvent's eventIdentifier, and which one we should use to identify calendar events across different devices. Specifically:
EKCalendarItem calendarItemExternalIdentifier The calendar item’s external identifier as provided by the calendar server. (read-only)
and
EKEvent eventIdentifier: A unique identifier for the event. (read-only)
EKCalendarItem calendarItemExternalIdentifier was added in iOS6, and I would have thought this would be the identifier I need to save to call later in EKEventStore eventWithIdenfier:
since it claims:
This identifier allows you to access the same event or reminder across multiple devices.
But in my own testing, it seems that when I create and save a new EKEvent, the eventIdenifier I get from the EKEvent object is unique and useful, and the calendarItemExternalIdentifier I get doesn't seem to work with EKEventStore eventWithIdenfier:
If someone has a conclusive answer, I would love to know.
calendarItemExternalIdentifier is the event's RFC 5545 globally unique identifier. It is not specific to EKEventStore, and indeed it represents that event across devices (as well as across non-iOS clients). If you were to open up an .ics attachment from your inbox, this value would be shown in the UID field of the invite.
That said, you cannot directly look up EKEventStore events based on this identifier. Instead, you'll need to do a predicate search on the event store and check the calendarItemExternalIdentifier on each event.
calendarItemExternalIdentifier can be looked up with
func calendarItemsWithExternalIdentifier(externalIdentifier: String) -> [EKCalendarItem]
Although availibility is marked with iOS 6.0, it may be undocumented (even private api) until recently. The interesting thing is, that you can get multiple Items back, so it should be possible to get all occurences of a recurring event (not yet tested)
Also the documentation of calendarItemExternalIdentifier seems to be updated, just for the sake of completeness, here it is:
This identifier allows you to access the same event or reminder across multiple devices. There are some cases where duplicate copies of a calendar item can exist in the same database:
A calendar item was imported from an ICS file into multiple calendars
An event was created in a calendar shared with the user and the user was also invited to the event
The user is a delegate of a calendar that also has this event
A subscribed calendar was added to multiple accounts
In such cases, you should choose between calendar items based on other factors, such as the calendar or source.
Recurring event identifiers are the same for all occurrences. If you wish to differentiate between occurrences, you may want to use the start date.
For Exchange servers, the identifier is different between iOS and OS X and different between devices for reminders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With