【发布时间】:2011-05-20 21:08:15
【问题描述】:
我想知道如何在 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 并不是我要寻找的。p>
谢谢!
编辑
我已经测试并得出结论,我最多只能获取 4 年的事件。有什么办法可以过去吗?不使用多次提取..
【问题讨论】:
-
需要过期事件列表吗?
-
没错,日历上的每个事件。过去和未来。
标签: iphone ios sdk fetch eventkit