Я пытаюсь программно добавить событие в календарь по умолчанию, но не могу найти, как я устанавливаю время, в которое происходит событие, и продолжительность события.Все, чего я достиг, выполнив ряд различных уроков, - это создание события на весь день, которое повторяется каждый день.Код, который у меня есть, приведен ниже.
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
// use this in the method that actually creates the event
NSError *err = nil;
//This date will be the date our reminder expires, as in stops recurring. Two years was chosen as most users
//will replace their device after 2 years
NSDate *fourteenWeeksFromNow = [NSDate dateWithTimeIntervalSinceNow:8467200];
//Define the recurrance rule
EKRecurrenceRule *recurrance;
NSDateComponents *comp = [[NSDateComponents alloc]init];
[comp setYear:0];
[comp setMonth:0];
[comp setDay:7];
//Recurr every 7 days I think but not working
recurrance = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyWeekly interval:1 end:[EKRecurrenceEnd recurrenceEndWithEndDate:fourteenWeeksFromNow]];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
//Our remind date
NSDate *eventDate = [cal dateByAddingComponents:comp toDate:[NSDate date] options:0]; // unsure what this does or how to use it
double alarmAmountInSeconds = 60.0*60.0*0.25; // 15 mins
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:(-1.0*alarmAmountInSeconds)]; // this is working correctly, alerts 15 minutes before
NSMutableArray *alarmsArray = [[NSMutableArray alloc] init];
[alarmsArray addObject:alarm];
[recurrenceRules arrayByAddingObject:recurrance];
event.title = module;
event.startDate = [[NSDate alloc] init]; // works
event.endDate = [[NSDate alloc] initWithTimeInterval:8467200 sinceDate:event.startDate]; // works
event.calendar = eventStore.defaultCalendarForNewEvents; // works
event.title = module; // works
event.allDay = FALSE; // dont want it all day but need to be able find out how to set time
event.location = @"Test location";
event.alarms = alarmsArray; // works
event.recurrenceRules = recurrenceRules; // not working could be problems with other attributes though
event.notes = @"This is a test"; // works
// Try to save the event
[eventStore saveEvent:event span:EKSpanFutureEvents error:&err];