Add Event in iCal or Calendar

iPhone SDK Tips & Tricks

Add EventKit.framework

#import <EventKit/EventKit.h>

EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *newEvent = [EKEvent eventWithEventStore:eventStore];


newEvent.title = @"Event Title";
newEvent.startDate = [NSDate date];
newEvent.endDate = certDatePicker.date;
//newEvent.location = event.location;
newEvent.notes = @"Note for the event";
//EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 Day
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-86400*30]; // 30 Day
EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-86400*60]; // 60 Day

[newEvent addAlarm:alarm1];
[newEvent addAlarm:alarm2];

[newEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:newEvent span:EKSpanThisEvent error:&err];