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 ...
Get iOS 5 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.