开发者

Add events to iCal from cocoa app

Is it possible to add events to iCal from my cocoa app? I tried using CalCalendarEvent but it didn't add anything to my calendar.

CalCalendarStore *calStore = [CalCalendarStore defaultCalendarStore];
CalEvent *event = [CalEvent event];

CalRecurrenceRule *recRule = [[CalRecurrenceRule alloc] initYearlyRecurrenceWithInterval:1 end:[CalRecurrenceEnd recurrenceEndWithOccurrenceCoun开发者_运维问答t:5]];
[event setRecurrenceRule:recRule];
[event setStartDate:currentDate];
[event setEndDate:endDate];
event.isAllDay = YES;

[calStore saveEvent:event span:CalSpanThisEvent error:NULL];

Thanks.


I think you are missing a CalCalendar object.
A minimal CalEvent looks like:

CalEvent* event = [CalEvent event]; event.calendar = calendar; //this is important - otherwise the event does not appear in iCal event.title = title; event.startDate = startDate; event.endDate = endDate;

You could also check saveEvent's NSError.
Update: As Mike Abdullah points out in his comment, NSError should be handled with care.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜