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

前端之家收集整理的这篇文章主要介绍了日历事件在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多次以及正确的事件.如图所示.

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

预期行为:事件应该从开始到结束日期只添加一次只有8AM …

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

谢谢..!

解决方法

尝试从下面的代码创建从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];

猜你在找的iOS相关文章