Add a new calendar to an EKEventStore with EventKit [closed]

送分小仙女□ 提交于 2019-12-04 11:43:13

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.

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

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!