4

I am using EventKit in my app and would like to find out what account a calendar belongs to.

The iPhone Calendar app shows all calendars grouped by account, with the account name for instance 'myname@me.com', or 'Gmail myname'. Where can I get those account names from?

I can get a list of EKCalendars from the EKEventStore and I can get each calendars title, but I have no idea where to get the account name from. Is there an official API for this? How else would I retrieve this information? Some apps on the App Store do display the account names, so there must be a way (that also slips through the approval process...)

Thanks, Thomas

Update: Somewhere else I found references to a private property. Before I start looking for that myself, does anybody know what the name of that property is?

Elsewhere people also suggested parsing the description (which includes the account), but that's not a very safe or elegant way, so I'd like to avoid doing that.

Update 2: I did find out that there is a private property (and its name) and it seems to work fine.

Thomas Müller
  • 15,565
  • 6
  • 41
  • 47
  • See [this question](http://stackoverflow.com/questions/6417632/how-to-access-an-ekcalendars-account-property) for info about the private API and a possible hack to avoid the use of private API in iOS 4.3. – puzzle Jun 20 '11 at 23:27

2 Answers2

2

I've looked through Apple's documentation and the account name doesn't seem to be available through the public API. Your app will be instantly rejected if you use a private property, so I suppose those other apps on the App Store use the desciption parsing method.

I suggest you post a bug report with Apple and request they make the account name available through the public API. Until they do (if they do), I think your only option is to parse the description if you want your app on the App Store

Erik B
  • 40,889
  • 25
  • 119
  • 135
1

Since iOS 5.0 you can access an EKSource from an EKCalendar. You can get the name & type of that source.

    EKEventStore * eventStore = [[EKEventStore alloc] init];
    NSArray * calendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];
    NSArray * typeNames = [[NSArray alloc] initWithObjects:@"TypeLocal",@"TypeExchange",@"TypeCalDAV",@"TypeMobileMe",@"TypeSubscribed",@"TypeBirthdays", nil];
    for (EKCalendar * calendar in calendars) {
        NSString * calendarTitle = calendar.title;
        EKSource * source = calendar.source;
        NSString * accountName = source.title;
        EKSourceType type = source.sourceType;
        NSLog(@"%@ : %@ (%@)", calendarTitle, accountName, typeNames[type]);
    }

The log generated looks like:

  • CalHotmail : Exchange (TypeExchange)
  • BirthHotmail (Read only) : Exchange (TypeExchange)
  • MyCoolAccountCal : Yahoo!‎ (TypeCalDAV)
  • Calendrier : Default (TypeLocal) Birthdays : Other (TypeBirthdays)
  • Calendrier : john.doe@mycooldomain.fr (TypeExchange)
  • ArnoTest : Gmail (TypeCalDAV)
  • Contacts' birthdays and events : Gmail (TypeCalDAV)
Arnaud SmartFun
  • 1,573
  • 16
  • 21