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

被刻印的时光 ゝ 提交于 2019-12-06 10:29:35

问题


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

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