Подтвердить что ты не робот

Событие календаря добавляет несколько раз при создании события в IOS

Я создал события календаря с сигналом тревоги за 5 минут до события.

Мое событие выглядит как

EKEvent <0x7fd8ae554ba0>
{
     EKEvent <0x7fd8ae554ba0>
{    title =        E-Cold
1mg; 
     location =     ; 
     calendar =     EKCalendar <0x7fd8ae717420> {title = Medicines; type = Local; allowsModify = YES; color = #1badf8;}; 
     alarms =       (
    "EKAlarm <0x7fd8ae71bd30> {triggerInterval = -300.000000}"
); 
     URL =          (null); 
     lastModified = 2015-03-18 09:01:41 +0000; 
     startTimeZone =    Asia/Kolkata (GMT+5:30) offset 19800; 
     startTimeZone =    Asia/Kolkata (GMT+5:30) offset 19800 
}; 
     location =     ; 
     structuredLocation =   (null); 
     startDate =    2015-03-18 02:30:00 +0000; 
     endDate =      2015-04-01 02:30:00 +0000; 
     allDay =       0; 
     floating =     0; 
     recurrence =   EKRecurrenceRule <0x7fd8ae720c40> RRULE FREQ=DAILY;INTERVAL=1;UNTIL=20150401T023000Z; 
     attendees =    (null); 
     travelTime =   (null); 
     startLocation =    (null);
};

Ниже мой код

EKEvent *event4 = [EKEvent eventWithEventStore:self.eventStore];                event4.title = @"E-Cold 1mg";
event4.startDate = pickerDate.date;                
event4.endDate = fourthEndcombDate;
EKRecurrenceEnd *endRecurrence = [EKRecurrenceEnd recurrenceEndWithEndDate:fourthEndcombDate];
EKRecurrenceRule *rule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval:1 end:endRecurrence];
[event4 addRecurrenceRule:rule];
event4.notes = @"Cure for Cold & Infection";
EKAlarm *alaram4 = [EKAlarm alarmWithRelativeOffset:aInterval];
[event4 addAlarm:alaram4];
[event4 setCalendar:self.defaultCalendar];
if (event4.availability != EKEventAvailabilityNotSupported) {
   event4.availability = EKEventAvailabilityFree;
}
NSError *err4 = nil;
[self.eventStore saveEvent:event4 span:EKSpanThisEvent commit:YES error:&err4];

Когда я добавляю событие с 8AM, как указано выше, он добавляет от даты начала до конца с 12AM несколько раз вместе с правильным событием. Как показано на изображениях.

Image with Event Time and Event with 12AM

Multiple events are adding along with correct event with 12AM

Является ли это поведением по умолчанию, или мне нужно что-то изменять во время создания события.

Ожидаемое поведение: событие должно быть добавлено один раз от начала до конца с 8AM только...

Пожалуйста, дайте советы или идеи, чтобы исправить это..!

Спасибо!..

4b9b3361

Ответ 1

Попробуйте использовать код ниже для создания события от startDate до даты окончания и просто удалите правило повторения, поскольку оно вызывает ваше событие.

EKEvent *event4 = [EKEvent eventWithEventStore:self.eventStore];
event4.title = @"E-Cold 1mg";
event4.startDate = pickerDate.date;                
event4.endDate = fourthEndcombDate;
event4.notes = @"Cure for Cold & Infection";
EKAlarm *alaram4 = [EKAlarm alarmWithRelativeOffset:aInterval];
[event4 addAlarm:alaram4];
[event4 setCalendar:self.defaultCalendar];
if (event4.availability != EKEventAvailabilityNotSupported) {
   event4.availability = EKEventAvailabilityFree;
}
NSError *err4 = nil;
[self.eventStore saveEvent:event4 span:EKSpanThisEvent commit:YES error:&err4];

Ответ 3

Если бы я понял, что это требование, это повторяющееся событие в 8 часов утра в период от даты начала до даты окончания. Событие event.startdate и event.enddate являются средними для указания конкретного события. Поэтому, если вы хотите, скажите, что событие повторяется с 19-07-2016 по 25-07-2016 в 8:00 ежедневно, сохраните событие следующим образом:

    event.startDate = selectedDateValue.date; //The start date value 19-07-2016 8 am
    event.endDate = selectedDateValue.date; //The start date value 19-07-2016 8 am. set the same start date value as the end date, so you will be able have the particular event bound to the 8am time frame of the calendar date.

    NSDate * reccuranceEndDate = selectedEndDateValue.date;//The end date value 25-07-2016 

    EKRecurrenceEnd *recurrenceEnd = [EKRecurrenceEnd recurrenceEndWithEndDate:reccuranceEndDate];
    EKRecurrenceRule *rule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval:1 end:recurrenceEnd];

    event.recurrenceRules = @[rule];