我刚刚运行了以下代码(在我的 iPhone 上):
let predicate = eventStore.predicateForEvents(withStart: Date(timeIntervalSinceNow: -60*60*24*365*4), end: Date(timeIntervalSinceNow: 60*60*24*30), calendars: [calendar])
结果显示这个请求只回溯了 3 年:
earliest start date found: 2015-04-11 12:00:00 +0000
有没有办法检索超过三年的日历事件?我想找回我以前的类笔记。当我在 Mac 上使用日历时,它会列出每个日历的计数,但我无法检索旧对象。
最佳答案
** 更新的答案 **
我深入研究了一下,发现了 following from Apple这解释了为什么 OP 有这个问题:
For performance reasons, this method matches only those events within a four year time span. If the date range between startDate and endDate is greater than four years, it is shortened to the first four years.
话虽如此,您可以使用以下代码作为示例创建四年的增量:
if let fourYearsAgo = Calendar.current.date(byAdding: .year, value: -4, to: Date()) {
let predicate = eventStore.predicateForEvents(withStart: fourYearsAgo,
end: Date(),
calendars: [calendar])
}
关于ios - 如何从 EKEventStore 检索 3 年前的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49326756/