I spent hours to track this bug.
My app is supposed to remove some events, then to add some other events. This works perfectly with iCloud and local calendars. However with Google calendars, this changes.
What I noticed so far:
- Sometimes all works perfectly. All events which should be removed are removed and all events that should be added are added.
- Sometimes, initially, all seems to be synced properly, but after 2 minutes, events get removed.
- .remove works better (95 %) than .save (50-80%).
- there are no catch errors. Neither for .remove, nor for .save.
It seems (?!) to be that Google calendars with few events (inside or outside the predicate - doesn't matter) gets synced correctly. Google calendars with many events (inside or outside the predicate) produce mentioned sync issues.
Here excerpts of the code (really nothing fancy!):
let evenStore = EventStore()
let predicate = eventStore.predicateForEvents(withStart: predicateStartDate!,
end: predicateEndDate!,
calendars: selectedCalendarArray)
let events = eventStore.events(matching: predicate)
for event in events {
do {
try eventStore.remove(event, span: .thisEvent, commit: false)
} catch {
print("event remove catch error")
}
}
... (new events are created and stored in eventsSave)
for event in eventsSave {
do {
try eventStore.save(event, span: .thisEvent, commit: false)
} catch {
print("event save catch error")
}
}
do {
try eventStore.commit()
} catch {
print("commit catch error")
}
I tried to avoid batch .remove or .save (true i.s.o. false - no commit()), No success.
I added eventStore.reset(). No success.
I added eventStore.refreshSourcesIfNecesary(). No success.
What I really don't get is, that iCloud works 100%. Google calendar is also a cloud calendar. What makes it behave so differently? There are some posts on SO, but they are mainly around 2013-2016. After that, virtually nothing anymore. Also never any solid solution, at the very best some workarounds.
Missing EKEvents when saving multiple Google calendar events
Batch saving EKEvents to Google calendar causing loss of random events
I am under the impression something basic and very simple is just missing, but no clue what this could be ...
Any help would be much appreciated!
UPDATE (06.08.2020)
Some events have geo location using the X-APPLE-STRUCTURED-LOCATION property. These events throw upon .save.
Error Domain=EKErrorDomain Code=19 "Locations with geo information are not supported by this account." UserInfo={NSLocalizedDescription=Locations with geo information are not supported by this account.}
Could this error be related to subject sync issue?
I believe I found the solution.
I use the calendar chooser to select a calendar. I store a default calendar in
myStoredCalendar(String) which should be preselected upon calendar chooser presentation.Above works, but generates the following log message (apart from subject Google event issues):
The following code doesn't produce error 1014 anymore, and all Google event issues are gone.
UPDATE (08.08.2021)
Above wasn't the solution. The error is totally random. Sometimes it works like charm for 20 times in a row, sometimes not a single run works properly.