I'm working on an app that uses EventKit to access calendar events. For users with external calendars like Google Calendar, they can sync these by adding the account through iOS Calendar settings. Once added, the events appear in my app as expected.
However, if a user adds a new event in Google Calendar, there’s often a delay before it appears in my app, since the iOS Calendar doesn't sync with external sources like Google in real time.
Currently, users can manually trigger a sync by opening the Apple Calendar app and using the pull-to-refresh feature under the "Calendars" tab. This works reliably but isn’t an ideal solution.
I tried using the EventKit method refreshSourcesIfNecessary()
to minimize the delay, as it claims to "[Pull] new data from remote sources, if necessary" (link to docs). I trigger this method when the app returns to the foreground. But, I'm not seeing the expected results. Here’s a typical sequence:
- Open my app and send it to the background.
- Add an event in Google Calendar.
- Return to my app.
Despite invoking refreshSourcesIfNecessary(),
the new event doesn’t appear in Apple Calendar (or accordingly in my app), until some random delay (30 seconds to several minutes). In contrast, the Apple Calendar app’s pull-to-refresh fetches the event immediately, every time.
Am I misinterpreting how refreshSourcesIfNecessary()
is intended to work? Or is there another way to achieve a faster sync with external calendars?