Search code examples
iphoneiosios5synchronizationeventkit

EventKit synchronization questions


In my app I'm using the EventKit API to access calendars on my device, and display them in my views. When working with network calendars, however, I suspect that EKEventStore will only return some sort of cached/local event list when queried, rather than reloading the calendar and return the actual/most recent contents.
When the native calendar app is launched instead, the app will refresh/reload all calendars, synchronizing any network shared calendars. Going back to my app will now also display the newly synchronized events.

In Addition to this, I found that modifying any events (delete/update) via my app and EventKit / EventKitUI will not sync back to e. g. my Mac's calendar.

To cut the long story short: Is there any way to force synchronization with network shared calendars in EventKit/iOS SDK?


Solution

    1. You can use the - (void)refreshSourcesIfNecessary method of an EKEventStore instance to:

      ... pull new data from remote sources if the local data is out of date.

      This would force an update of the local calendar store by fetching the latest remote data. I have a feeling this is the method the native iOS Calendar app is using to prompt an update.

    2. As for the issue with deleted and updated calendar events not syncing to your Mac, are you sure you are calling - (void)commit: on your EKEventStore instance after you have made your modifications?

      Alternatively, there is a selection of methods within EKEventStore for saving and remove calendars and events that also offer a commit parameter which can immediately commit your changes. I would post the links but as a new user I can only use two hyperlinks.

      - (void)saveEvent:span:commit:error:
      - (void)removeEvent:span:commit:error:

      Assuming these events are being added to a cloud based calendar, this should have the effect of synchronising your changes to your Mac.