Error when saving EKEvent into EKEventStore (exporting to calendar)

Viewed 368

My automated report has been showing a growing issue in exporting into the user calendars with the error:

NSInternalInconsistencyException 
Trying to set the object ID on an object that has one!

When I'm calling

do {
  try store.save(event, span: .thisEvent)
  return event.eventIdentifier
} catch {
  Log.error(error.localizedDescription)
}

I'm currently having a hard time reproducing the error, or even finding any open topics online. It seems to be happening on iOS 14. Has someone faced it? Any suggestions?

1 Answers

I had same problem and I found solution. Do store.save in main thread.

DispatchQueue.main.async {
            do {
                try self.eventStore.save(event, span: .thisEvent)
                
            } catch let error as NSError {
                print("failed to save event with error : \(error)")
            }
            
        }
Related