- (EKCalendar *) calDAVCalendarWithTitleContaining
:(NSString *)paramDescription{
EKCalendar *result = nil;
EKEventStore *eventStore = [[EKEventStore alloc] init];
for (EKCalendar *thisCalendar in eventStore.calendars){
if (thisCalendar.type == EKCalendarTypeCalDAV){
if ([thisCalendar.title
rangeOfString:paramDescription].location != NSNotFound){
return thisCalendar;
}
}
}
return result;
}
- (void) readEvents{
/* Find a calendar to base our search on */
EKCalendar *targetCalendar =
[self calDAVCalendarWithTitleContaining:@"gmail.com"];
/* If we could not find a CalDAV calendar that we were looking for,
then we will abort the operation */
if (targetCalendar == nil){
NSLog(@"No CalDAV calendars were found.");
return;
}
/* We have to pass an array of calendars to the event store to search */
NSArray *targetCalendars = [[NSArray alloc] initWithObjects:
targetCalendar, nil];
/* Instantiate the event store */
EKEventStore *eventStore = [[EKEventStore alloc] init];
/* The start date will be today */
NSDate *startDate = [NSDate date];
/* The end date will be one day from today */
NSDate *endDate = [startDate dateByAddingTimeInterval:24 * 60 * 60];
/* Create the predicate that we can later pass to the
event store in order to fetch the events */
NSPredicate *searchPredicate =
[eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:targetCalendars];
/* Make sure we succeeded in creating the predicate */
if (searchPredicate == nil){
NSLog(@"Could not create the search predicate.");
return;
}
/* Fetch all the events that fall between
the starting and the ending dates */
NSArray *events = [eventStore eventsMatchingPredicate:searchPredicate];
/* Go through all the events and print their information
out to the console */
if (events != nil){
NSUInteger counter = 1;
for (EKEvent *event in events){
NSLog(@"Event %lu Start Date = %@",
(unsigned long)counter,
event.startDate);
NSLog(@"Event %lu End Date = %@",
(unsigned long)counter,
event.endDate);
NSLog(@"Event %lu Title = %@",
(unsigned long)counter,
event.title);
counter++;
}
} else {
NSLog(@"The array of events for this start/end time is nil.");
}
}
- (BOOL) application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self readEvents];
self.window = [[UIWindow alloc] initWithFrame:
[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}