首页 > 解决方案 > 将 EKEvent 保存到 EKEventStore 时出错(导出到日历)

问题描述

我的自动报告在导出到用户日历时显示了一个日益严重的问题,并出现错误:

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

当我打电话时

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

我目前很难重现该错误,甚至无法在线找到任何开放主题。它似乎发生在 iOS 14 上。有人遇到过吗?有什么建议么?

标签: iosswift

解决方案


我有同样的问题,我找到了解决方案。在主线程中进行 store.save 。

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

推荐阅读