从 EventStore EventKit iOS 获取所有事件
我想知道如何在 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
as startDate 和 endDate,但没有效果。 所以其他 Q 中的其他 A 并不是我正在寻找的。
谢谢你!
编辑
我已经测试并得出结论,我只能获取最多 4 年时间内的事件。有办法克服这个吗?不使用多次获取..
i would like to know how to fetch all events from an EventStore using EventKit in iOS.
This way i can specify all events for today:
- (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;
}
The correct should use a NSPredicate, which is created with:
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];
I have tried using
distantPast
distantFuture
as startDate and endDate, no good.
So other A's from other Q's are not exaclty wha im looking for.
Thank you!
EDIT
I have tested and got to the conclusion that i can only fetch events in a period of 4 years maximum. Any way of getting past this? Without using multiple fetches..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将所有事件提取到数组中的代码:
Code for fetch all events into array :
这是我在应用程序中使用的方法来获取它们。
This is the method I am using in my app to fetch them.
这是生产中的代码
对于您来说,我建议您回顾和展望十年。
This is code in production
For you, I would recommend looking back and forward ten years.