10

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..!

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59
  • whre is your created code for this stuff..? you are atteched images with this question but real code Main thing is your created code for add event in calender. Probably i think thre is add event code in Loop and that added multiple times. – Nitin Gohel Mar 18 '15 at 10:53
  • I have edited my question and added code for reference. I am not using any loop... – Vidhyanand Mar 18 '15 at 11:13
  • You have setup a two-week long event to repeat every day. Why would you do that? – rmaddy Jan 19 '16 at 04:20

3 Answers3

2

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];
Dheeraj Singh
  • 5,143
  • 25
  • 33
  • If I remove recurrenceRule then it is working as expected only..But with recurrence rule this issue is coming....!As per my requirement my event should persist from startDate to EndDate..! – Vidhyanand Mar 18 '15 at 14:25
  • If I remove recurrence then event is adding with 12AM between start Date and end Date.!It must add with 8AM not 12AM..Means on 18Mar it is adding with 8AM after that from 19Mar - 1 Apr it is adding with 12AM..only.(In this case duplicates is removed but the event time is getting wrong) – Vidhyanand Mar 18 '15 at 14:31
  • have u tried creating a event with your requirements in default calendar ?it will generate u with the event continously for the second day too. – Dheeraj Singh Mar 19 '15 at 05:02
  • Same result when added manually using default calendar of the device. If recurrence/repeat is set to Never then the duplicates are removing but same other than start date rest of all the dates the event is adding with 12AM..instead of 8AM..It is bug or default...? – Vidhyanand Mar 19 '15 at 11:14
  • it is the default implementation of calendar and i too had the same problem. – Dheeraj Singh Mar 19 '15 at 11:15
  • so if u want to add a continuous day event it will add it in the same way and the second day event will be continuous too. – Dheeraj Singh Mar 19 '15 at 11:17
  • Fine..But it looks odd when we see multiple events are adding in calendar..along with exact event time. Any fix with the use of calendar properties..! – Vidhyanand Mar 19 '15 at 11:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73326/discussion-between-dheeraj-singh-and-vidhyanand900). – Dheeraj Singh Mar 19 '15 at 11:26
1

Try changing the last line of your code to this:

[self.eventStore saveEvent:event4 span:EKSpanFutureEvents commit:YES error:&err4];

https://developer.apple.com/library/ios/documentation/EventKit/Reference/EKEventStoreClassRef/index.html#//apple_ref/swift/struct/EKSpan

Pittmyster
  • 62
  • 4
0

If I got you right, the requirement is a recurrent event at 8 am for the period from start date to your end date. The event.startdate and event.enddate are mean to specify a particular event. So if you want to have, say an event to repeat from 19-07-2016 to 25-07-2016 at 8 am daily, save the event as follows:

    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];
Tony
  • 53
  • 9