首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用EventKit向EKEventStore添加新日历

使用EventKit向EKEventStore添加新日历
EN

Stack Overflow用户
提问于 2011-10-30 22:43:09
回答 2查看 4.8K关注 0票数 3

如何在iOS 5中将日历(而不是事件)添加到EKEventStore?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-11 13:48:05

我捕获了一个异常,除非我也这样做了:

代码语言:javascript
复制
// 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;

当然,看看其他的EKSourceType枚举,看看哪一个更适合您的需求。

票数 2
EN

Stack Overflow用户

发布于 2011-10-31 02:04:09

代码语言:javascript
复制
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....

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7945537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档