开发者

Add events to iCal from cocoa app

开发者 https://www.devze.com 2022-12-16 01:38 出处:网络
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.

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

精彩评论

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