Pradeep Nayak
Pradeep Nayak

Reputation: 675

programatically adding a calendar event on iPad

I have a button on my iPad, on clicking it, an entry on the calendar should be created with a specific title and default time duration of 30min. How can I do that ? I have reached a point where I have inheritted the calendar object and also able to read it also.

Question: How do I add the entry to it from the code ?

Upvotes: 2

Views: 2648

Answers (1)

Saurabh
Saurabh

Reputation: 22873

I pasted this from my code... post a comment if you have any confusion

EKEventStore *eventStore = [[EKEventStore alloc] init];

EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
event.title     = @"EVENT TITLE";
event.notes     = @"Event notes here";
event.startDate = [[NSDate alloc] init];
event.endDate   = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];

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

Upvotes: 4

Related Questions