I've been looking at adding iCal support to my new application and everything seemed just fine and worked on my Mac OS X 10.6 Snow Leopard development machine without a hitch.
Now it looks like depending on what is in your calendar the very simple query below:
- (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( @"fet开发者_高级运维ch took: %f seconds", [NSDate timeIntervalSinceReferenceDate] - start );
return events;
}
produces a beachball thrash even with quite limited events in the calendar store.
Am I missing something crucial here? The code snippet is pretty much exactly from the documentation at:
// 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];
It looks like it has something to do with the recurrence rules, but as far as I can see there are no other ways of fetching events from the calendar store anyway.
Has anybody else come across this?
Best regards,
Frank
精彩评论