从 iOS 5.0 开始,您可以从 EKCalendar 访问 EKSource。您可以获得该来源的名称和类型。
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]);
}
生成的日志如下所示:
- CalHotmail : 交换 (TypeExchange)
- BirthHotmail (只读) : Exchange (TypeExchange)
- MyCoolAccountCal : Yahoo! (TypeCalDAV)
- 日历:默认(TypeLocal)生日:其他(TypeBirthdays)
- 日历:john.doe@mycooldomain.fr (TypeExchange)
- ArnoTest:Gmail (TypeCalDAV)
- 联系人的生日和活动:Gmail (TypeCalDAV)