简单的CalendarStore查询将应用程序置于无限循环中?

时间:2010-04-15 19:38:47

标签: objective-c cocoa macos icalendar

我一直在寻找为我的新应用程序添加iCal支持,一切似乎都很好,并且在我的Mac OS X 10.6 Snow Leopard开发机器上顺利工作。

现在看来,根据日历中的内容,下面是一个非常简单的查询:

- (NSArray*) fetchCalendarEventsForNext50Minutes {

NSLog(@"fetchCalendarEventsForNext50Minutes");

NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];

NSDate* startDate = [[NSDate alloc] init];
NSDate* endDate = [startDate addTimeInterval: 50.0 * 60.0];

NSPredicate *eventsForTheNext50Minutes = [CalCalendarStore eventPredicateWithStartDate:startDate endDate:endDate
                                         calendars:[[CalCalendarStore defaultCalendarStore] calendars]];


// Fetch all events for this year
NSArray *events = [[CalCalendarStore defaultCalendarStore] eventsWithPredicate: eventsForTheNext50Minutes];

NSLog( @"fetch took: %f seconds", [NSDate timeIntervalSinceReferenceDate] - start );

return events;

}
即使在日历商店中活动非常有限,

也会产生沙滩球捶打。

我错过了一些关键的东西吗?代码片段完全来自以下文档:

// Create a predicate to fetch all events for this year
NSInteger year = [[NSCalendarDate date] yearOfCommonEra];
NSDate *startDate = [[NSCalendarDate dateWithYear:year month:1 day:1 hour:0 minute:0     second:0 timeZone:nil] retain];
NSDate *endDate = [[NSCalendarDate dateWithYear:year month:12 day:31 hour:23 minute:59 second:59 timeZone:nil] retain];
NSPredicate *eventsForThisYear = [CalCalendarStore eventPredicateWithStartDate:startDate endDate:endDate
calendars:[[CalCalendarStore defaultCalendarStore] calendars]];

// Fetch all events for this year
NSArray *events = [[CalCalendarStore defaultCalendarStore]     eventsWithPredicate:eventsForThisYear];

看起来它与重复规则有关,但据我所知,没有其他方法可以从日历存储中获取事件。

还有其他人遇到过这个吗?

致以最诚挚的问候,

0 个答案:

没有答案