Let's say I have to write an application that must sync with one of the calendars available on the device. Let's assume that I have "Action" objects that have a start date, end date, recurrence etc.
Device A: I create "Action" objects and then sync them using EventKit with my iCloud calendar named "Foo". I get some unique identifiers that I have to link them with my "Action" objects in order to know which one to update/delete in the future. Then I sync my "Action" objects with my own server.
Device B: I get the "Action" objects from the server. I modify them. I have to update the calendar items. What happens if I don't have the "Foo" calendar set on Device B? What happens if I do have it?
I guess I need to use the calendarItemExternalIdentifier
and not the calendarItemIdentifier
property in order to identify events uniquely across devices that use the same calendar, right?
Is that calendarItemExternalIdentifier
given in the moment of creation of the calendarItem? or is it given by the iCloud server? Do I need internet connection for this to work?
The documentation for the calendarIdentifier
property states:
A full sync with the calendar will lose this identifier. You should have a plan for dealing with a calendar whose identifier is no longer fetch-able by caching its other properties.
What does a full sync even mean?
calendarItemExternalIdentifier
is available as soon as you save (with commit) a calendar item. But, there are situations when the calendarItemExternalIdentifier
is later changed, when the calendar item is synced further to the server (e.g. if it's an event from an Exchange account).
All the other identifiers are not shared between devices (this includes identifiers for sources and calendars), so the best option is sticking with calendarItemExternalIdentifier
.
A full sync with a calendar can occur when the user sets up a new source (e.g. the user removes and adds the same Exchange account). There may also be different situations that cause a full calendar sync.calendarIdentifier
is a local identifier, so it won't be of much use in your case (except if you want to create a workaround for the issue with calendarItemExternalIdentifier
changing).
As mentioned earlier, the calendar and source identifiers are not global, so it would be near impossible to know if "Foo" calendar is setup on a different device, or if the "Foo" calendar is the same "Foo" calendar from your other device.
Usually, if you find your Action object on the new device, you can assume that the calendar that it belongs to is the same as the calendar from the different device.
One way to go about it, when updating your Action objects, would be to save the changes (as usual) to the server. Each of the devices (including the one that made the change) would then search for the corresponding calendar item, and update it if it's found.
I'm currently doing something similar, and this is probably what I'll end up doing.
A better alternative (probably more time consuming as well) would be to have the server connect and sync with the external sources (CalDav, Exchange etc.).
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