Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

ios - How to identify EKEvent uniquely with Sync across the devices

I am trying to make Event Syncing feature for a Project. I need to sync events with the remote server.

  • Let's say I Installed the App in Device A.
  • If I login to another device lets take B, then events synced from A should also appear in Device B, and events of B should also be synced.
  • Now if I again login into the Device A, Events of B should be added.But events previously from A should not again be added to Device A again For this I decided to keep its eventIdentifier on the remote database.
  • The Issue now happens when I again Go back to Device B, where events previously synced from Device A are already there, so those events should not be added again. But as eventIdentifiers were as per Device A, there is no way to Identify if the event is already added in Device B or not.

Can anyone suggest me the way to achieve such cross-platform event syncing without duplication of the event?

EKEvent has property eventIdentifier, but it's only readOnly property and I can't keep event's remote ID somewhere.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

Using calendarItemExternalIdentifier you can check if an event was already added by querying to see if there's already a record with the same calendarItemExternalIdentifier in your database. The exception described above needs to be handled separately.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...