O'Reilly logo

iOS 5 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.1. Retrieving the List of Calendars

Problem

You want to retrieve the list of calendars available on the user’s device before you attempt to insert new events into them.

Solution

Access the calendars array property of an instance of EKEventStore. Each calendar is of type EKCalendar:

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ EKEventStore *eventStore = [[EKEventStore alloc] init]; /* These are the calendar types an iOS Device can have. Please note that the "type" property of an object of type EKCalendar is of type EKCalendarType. The values in the "CalendarTypes" array reflect the exact same values in the EKCalendarType enumeration, but as NSString values */ NSArray *calendarTypes = [[NSArray alloc] initWithObjects: @"Local", @"CalDAV", @"Exchange", @"Subscription", @"Birthday", nil]; /* Go through the calendars one by one */ NSUInteger counter = 1; for (EKCalendar *thisCalendar in eventStore.calendars){ /* The title of the calendar */ NSLog(@"Calendar %lu Title = %@", (unsigned long)counter, thisCalendar.title); /* The type of the calendar */ NSLog(@"Calendar %lu Type = %@", (unsigned long)counter, [calendarTypes objectAtIndex:thisCalendar.type]); /* The color that is associated with the calendar */ NSLog(@"Calendar %lu Color = %@", (unsigned long)counter, [UIColor colorWithCGColor:thisCalendar.CGColor]); /* And whether the calendar can be modified or not */ if ([thisCalendar allowsContentModifications]){ NSLog(@"Calendar ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required