iPhone Event Kit:以编程方式创建EKCalendar?

Tho*_*lin 8 iphone

我想在我的应用程序中插入事件,因此可以在iPhone Calendar.app中查看它们.但由于我不想将用户事件与我的应用程序中的用户事件混合,我想创建一个类似"MyApp Events"的EKCalendar

这可能吗 ?除非您如何过滤您的活动?

谢谢 !

kur*_*arc 12

绝对有可能创建自己的日历 - 问题是您需要iOS 5:

EKEventStore* eventStore = [[EKEventStore alloc] init];
NSString* calendarName = @"My Cal";
EKCalendar* calendar;

// 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;
calendar.title = calendarName;

NSError* error;
bool success= [eventStore saveCalendar:calendar commit:YES error:&error];
if (error != nil)
{
    NSLog(error.description);
    // TODO: error handling here
}
Run Code Online (Sandbox Code Playgroud)