December 2012
Intermediate to advanced
834 pages
27h
English
You would like to be able to create new events in users’ calendars.
Find the calendar you want to insert your event into (please refer
to Recipe 16.1). Create an
object of type EKEvent using the
eventWithEventStore: class method of
EKEvent and save the event into the
user’s calendar using the saveEvent:span:error: instance method of
EKEventStore:
-(BOOL)createEventWithTitle:(NSString*)paramTitlestartDate:(NSDate*)paramStartDateendDate:(NSDate*)paramEndDateinCalendarWithTitle:(NSString*)paramCalendarTitleinCalendarWithType:(EKCalendarType)paramCalendarTypenotes:(NSString*)paramNotes{BOOLresult=NO;EKEventStore*eventStore=[[EKEventStorealloc]init];/* Are there any calendars available to the event store? */if([eventStore.calendarscount]==0){NSLog(@"No calendars are found.");returnNO;}EKCalendar*targetCalendar=nil;/* Try to find the calendar that the user asked for */for(EKCalendar*thisCalendarineventStore.calendars){if([thisCalendar.titleisEqualToString:paramCalendarTitle]&&thisCalendar.type==paramCalendarType){targetCalendar=thisCalendar;break;}}/* Make sure we found the calendar that we were asked to find */if(targetCalendar==nil){NSLog(@"Could not find the requested calendar.");returnNO;}/* If a calendar does not allow modification of its contentsthen we cannot insert an event into it */if(targetCalendar.allowsContentModifications==NO){NSLog(@"The selected calendar ...
Read now
Unlock full access