问题
I'm looping through around 100 objects that create an event for each using EventKit. I don't "commit" until all the objects are saved and know a calendarIdentifier is successfully fetched for each. Yet about 10-15% of the events never show on the device calendar or online. This only happens with Google Calendar. iCloud and local work fine.
I understood when creating multiple events like this, it was preferable to use:
[eventStore saveEvent:event span:EKSpanThisEvent commit:NO error:&error];
...and
[eventStore commit:&error];
...after all events have been created. I also tried committing through each loop and predictably got errors around communication being interrupted. Appreciate any help.
回答1:
I met similar problem. My issue happens when I delete an EKEvent instance, then save a new EKEvent instance immediately. Sometimes (maybe 3 out of 5), the deleted event appears again. The deletion did not return any error. For me, it looks like it did not submit successfully, then the EKEventStore rolled back that "should be deleted" event by itself. I tried all different ways to handle the processing, for example, with the commit set to Yes or No, request access again and only access granted is Yes then start the process. But there is no difference. I spent several nights trying to figure out what caused that but had no clue.
Then I added the deleted EKEvent's eventIdentifier to an array and verify a second time (just before I fetch events). If it is still there, delete it again. So far it works well. It's a dirty solution but at least it works.
So I suggest other users try similar solutions when they do batch operations with Google Calendars using EventKit. Check again the eventIdentifiers before next fetch. If some eventIdentifiers should be or should not be there (using [EKEventStore eventWithIdentifier]), add it again or delete it again.
Just my 2 cents.
来源:https://stackoverflow.com/questions/34424854/missing-ekevents-when-saving-multiple-google-calendar-events