How to Uniquely Identify EKEvent with Device Sync

I am trying to make an event synchronization function for a project. I need to synchronize events with a remote server.

  • Say I installed the application on device A.
  • If I log into the system on another device, take B, events synchronized with A should also appear on device B, and events B should also be synchronized
  • Now, if I log in to device A again, I should add events B. But events, earlier from A, should not be added to device A again . For this, I decided to store its eventIdentifier in a remote database.
  • The problem now arises when I return to device B again, where events previously synchronized with device A already exist, so these events should not be added again. But since eventIdentifiers corresponds to device A, there is no way to determine if an event has been added to device B or not.

Can someone suggest me a way to achieve such cross-platform event synchronization without duplicating the event?

EKEvent has an eventIdentifier property, but it is only a readOnly property, and I cannot save the event identifier somewhere.

0
source share
1 answer

eventIdentifier not shared between devices - the same event will most likely have different eventIdentifier on different devices.

Instead, you need to use calendarItemExternalIdentifier - this will (usually) be the same on different devices.
One (relatively rare) exception is when an event was recently created using EventKit, and this event has not yet been synchronized with the server. This causes the calndarItemExternalIdentifier to change at a later time .

Using calendarItemExternalIdentifier , you can check if an event has already been added by querying to see if there is an entry in your database with the same calendarItemExternalIdentifier . The exception described above must be handled separately.

+1
source

Source: https://habr.com/ru/post/901420/


All Articles