December 2012
Intermediate to advanced
834 pages
27h
English
You want to add alarms to the events in a calendar.
Use the alarmWithRelativeOffset: class method of
EKAlarm to create an instance of
EKAlarm. Add the alarm to an event
using the addAlarm: instance method
of EKEvent, like so:
-(EKCalendar*)getFirstModifiableLocalCalendar{EKCalendar*result=nil;EKEventStore*eventStore=[[EKEventStorealloc]init];for(EKCalendar*thisCalendarineventStore.calendars){if(thisCalendar.type==EKCalendarTypeLocal&&[thisCalendarallowsContentModifications]){returnthisCalendar;}}returnresult;}-(void)addAlarmToCalendar{EKCalendar*targetCalendar=[selfgetFirstModifiableLocalCalendar];if(targetCalendar==nil){NSLog(@"Could not find the target calendar.");return;}EKEventStore*eventStore=[[EKEventStorealloc]init];/* The event starts 60 seconds from now */NSDate*startDate=[NSDatedateWithTimeIntervalSinceNow:60.0f];/* And end the event 20 seconds after its start date */NSDate*endDate=[startDatedateByAddingTimeInterval:20.0f];EKEvent*eventWithAlarm=[EKEventeventWithEventStore:eventStore];eventWithAlarm.calendar=targetCalendar;eventWithAlarm.startDate=startDate;eventWithAlarm.endDate=endDate;/* The alarm goes off two seconds before the event happens */EKAlarm*alarm=[EKAlarmalarmWithRelativeOffset:-2.0f];eventWithAlarm.title=@"Event with Alarm";[eventWithAlarmaddAlarm:alarm];NSError*saveError=nil;if([eventStoresaveEvent:eventWithAlarm ...
Read now
Unlock full access