问题
How can I add a Calendar (not an event) to a EKEventStore in iOS 5?
回答1:
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.
回答2:
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....
}
来源:https://stackoverflow.com/questions/7945537/add-a-new-calendar-to-an-ekeventstore-with-eventkit