在IOS中创建事件时,日历事件正在多次添加

Vid*_*and 10 objective-c ios ekevent

我在活动开始前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);
};
Run Code Online (Sandbox Code Playgroud)

以下是我的代码

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];
Run Code Online (Sandbox Code Playgroud)

当我像上面那样添加8AM事件时,它会从开始日期到结束日期多次添加12AM以及正确的事件.如图所示.

带有事件时间和事件的图像,上午12点

多个事件与12AM的正确事件一起添加

它是默认行为还是我需要在创建事件时修改任何内容.

预期行为:事件应该从开始结束到结束日期仅添加8AM ...

请提出建议或想法来解决这个问题..!

谢谢..!

Dhe*_*ngh 2

尝试使用下面的代码来创建从开始日期到结束日期的事件,然后删除重复规则,因为它会使您的事件重复发生。

\n\n
EKEvent *event4 = [EKEvent eventWithEventStore:self.eventStore];\nevent4.title = @\xe2\x80\x9cE-Cold 1mg\xe2\x80\x9d;\nevent4.startDate = pickerDate.date;                \nevent4.endDate = fourthEndcombDate;\nevent4.notes = @\xe2\x80\x9cCure for Cold & Infection\xe2\x80\x9d;\nEKAlarm *alaram4 = [EKAlarm alarmWithRelativeOffset:aInterval];\n[event4 addAlarm:alaram4];\n[event4 setCalendar:self.defaultCalendar];\nif (event4.availability != EKEventAvailabilityNotSupported) {\n   event4.availability = EKEventAvailabilityFree;\n}\nNSError *err4 = nil;\n[self.eventStore saveEvent:event4 span:EKSpanThisEvent commit:YES error:&err4];\n
Run Code Online (Sandbox Code Playgroud)\n