How can I add a Calendar (not an event) to a EKEventStore in iOS 5?
Asked
Active
Viewed 4,790 times
2 Answers
2
I caught an exception unless I also did:
// Get the calendar source
EKSource* localSource;
for (EKSource* source in eventStore.sources) {
if (source.sourceType == EKSourceTypeLocal)
{
localSource = source;
break;
}
}
if (!localSource)
return;
calendar = [EKCalendar calendarWithEventStore:eventStore];
calendar.source = localSource;
Naturally, take a look at the other EKSourceType enums to see which one is appropriate for your needs.

kurtzmarc
- 3,110
- 1
- 24
- 40
1
EKEventStore *calendarStore = [[EKEventStore alloc] init];
EKCalendar *calendar = [EKCalendar calendarWithEventStore:calendarStore];
NSString *calendarID = [calendar calendarIdentifier]; /// cache this in your app data for retrieval later
[calendar setTitle:@"New Calendar"];
NSError *error = nil;
BOOL saved = [calendarStore saveCalendar:calendar commit:YES error:&error];
if (!saved) {
// handle error....
}

falconcreek
- 4,170
- 1
- 21
- 22
-
1saving without a source results in an error – Corey Floyd Mar 04 '12 at 03:24
-
all this only adds a calendar which cannot be seen from the default calendar app for me. did anyone face a similar issue? is there something I may have missed..or have to add? – codeburn Aug 01 '13 at 04:46