Search code examples
objective-cioscocoa-toucheventkit

Add a new calendar to an EKEventStore with EventKit


How can I add a Calendar (not an event) to a EKEventStore in iOS 5?


Solution

  • 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.