ios - 如何从 EKEventStore 检索 3 年前的事件

标签 ios swift eventkit ekeventstore

我刚刚运行了以下代码(在我的 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/

相关文章:

ios - EventKit,保存事件时出错 : The repeat field cannot be changed.

iphone - 在核心数据中保存一对多关系时出现问题

ios - 如何设置UIDatePicker仅几个月

ios - HKSampleQuery 只会返回过去 7 天的值吗?

ios - 刷新 TableView 除了拉动刷新

swift - 如何在Swift中读取和写入大块内存中的位

objective-c - 使用 EK 事件、EventKit 未显示事件标题

iphone - EventKit EKEvent "organizer"属性的目的/用途是什么?

如果方向改变,ios 处理parentViews

ios - 将iOS App从一个账户的Testflight转移到另一个账户