我想知道如何在 iOS 中使用 EventKit 从 EventStore 中获取所有事件。
这样我可以指定今天的所有事件:
- (NSArray *)fetchEventsForToday {
NSDate *startDate = [NSDate date];
// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];
// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];
// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
return events;
}
正确的应该使用 NSPredicate,它是通过以下方式创建的:
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];
我试过使用
distantPast
distantFuture
作为 startDate 和 endDate,不好。因此,来自其他 Q 的其他 A 并不是我正在寻找的确切内容。
谢谢!
编辑
我已经测试并得出结论,我最多只能在 4 年内获取事件。有什么办法可以过去吗?不使用多次提取..