Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar Event is adding Multiple times when creating Event in IOS

I am created an Calendar Events with Alarm 5 min before the event.

My Event looks like this

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);
};

Below is my code

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];

When I add event with 8AM like above then it is adding from start date to end date with 12AM multiple times along with correct event..As shown in images.

Image with Event Time and Event with 12AM

Multiple events are adding along with correct event with 12AM

Is it default behavior or I need to modify anything while creating event.

Expected Behaviour: Event should be added once from start end to end date with 8AM only...

Please give suggestions or ideas to fix this..!

Thanks..!

like image 483
Vidhyanand Avatar asked Mar 18 '15 09:03

Vidhyanand


1 Answers

Try Out the Below Code to Create Event from startDate to End Date and just remove the recurrence Rule as it is making your event recuure.

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];
like image 121
Dheeraj Singh Avatar answered Sep 21 '22 13:09

Dheeraj Singh