是否可以从我的 cocoa 应用程序向 iCal 添加事件?我尝试使用 CalCalendarEvent 但它没有向我的日历添加任何内容。
CalCalendarStore *calStore = [CalCalendarStore defaultCalendarStore];
CalEvent *event = [CalEvent event];
CalRecurrenceRule *recRule = [[CalRecurrenceRule alloc] initYearlyRecurrenceWithInterval:1 end:[CalRecurrenceEnd recurrenceEndWithOccurrenceCount:5]];
[event setRecurrenceRule:recRule];
[event setStartDate:currentDate];
[event setEndDate:endDate];
event.isAllDay = YES;
[calStore saveEvent:event span:CalSpanThisEvent error:NULL];
谢谢。
最佳答案
我认为您缺少 CalCalendar
对象。
最小的 CalEvent
如下所示:
CalEvent* 事件 = [CalEvent 事件]; 事件.日历 = 日历;//这很重要 - 否则该事件不会出现在 iCal 中 事件.标题 = 标题; event.startDate = 开始日期; event.endDate = endDate;
您还可以检查 saveEvent
的 NSError。
更新: 正如 Mike Abdullah 在评论中指出的那样,NSError 应该是 handled with care .
关于objective-c - 从 cocoa 应用程序将事件添加到 iCal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2033103/