EKEvent is not added according to EKRecurrenceRule

1k Views Asked by At

I'm trying to create a repeatitive event on calendar. I've created an EKRecurrenceRule and set it to that event. But the event is not created according to my recurrence rule.

Here is my code,

        //just creating a recurrence rule for RRULE:FREQ=YEARLY;BYMONTH=6,7;BYDAY=1TH
        // setting the values directly for testing purpose.

        EKRecurrenceEnd *endRecurrence = nil;                                         
        NSMutableArray *monthsOfTheYearArray = [NSMutableArray array];               
        NSMutableArray *daysOfTheWeekArray = [NSMutableArray array]; 

        //BYMONTH=6,7 (6 for june, 7 for july)
        [monthsOfTheYearArray addObject:[NSNumber numberWithInt:6]];
        [monthsOfTheYearArray addObject:[NSNumber numberWithInt:7]];

        //BYDAY=1TH
        [daysOfTheWeekArray addObject:[EKRecurrenceDayOfWeek dayOfWeek:5 weekNumber:1]];
        endRecurrence = [EKRecurrenceEnd recurrenceEndWithEndDate:[self dateFromString:@"2018-12-15T22:30+06:00"]];


        //create the recurrence rule here
        EKRecurrenceRule *recurrence = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency: EKRecurrenceFrequencyYearly

                                                                                    interval:1
                                                                               daysOfTheWeek:daysOfTheWeekArray
                                                                              daysOfTheMonth:nil
                                                                             monthsOfTheYear:monthsOfTheYearArray
                                                                              weeksOfTheYear:nil
                                                                               daysOfTheYear:nil
                                                                                setPositions:nil
                                                                                         end:endRecurrence];



        //setting the values for creating the event here
        EKEventStore *eventStore = [[EKEventStore alloc] init];
        EKEvent *event = [EKEvent eventWithEventStore:eventStore];
        event.title = @"testRecurrenceRule";
        event.location = @"Dhaka";
        [event setCalendar:[eventStore defaultCalendarForNewEvents]];
        event.startDate = [self dateFromString:@"2013-06-18T21:00:00+06:00"];
        event.endDate = [self dateFromString:@"2013-06-18T22:00:00+06:00"];
        [event addRecurrenceRule: recurrence];

        //save the event into calendar.
        [self saveTheEvent:event eventStore:eventStore];

With this code events are being created only on each each 1st thursday of month June, Why July is being skipped?
Please let me know why the event is not being created according to the recurrence rules I've set.

1

There are 1 best solutions below

0
On

Ok. In the document EKRecurrenceDayOfWeek Class Reference, it says

A day of the week can optionally have a week number, indicating a specific day in the recurrence rule’s frequency. For example, a day of the week with a day value of Tuesday and a week number of 2 would represent the second Tuesday of every month in a monthly recurrence rule, and the second Tuesday of every year in a yearly recurrence rule. A day of the week with a week number of 0 ignores its week number.

You are doing frequency yearly, so it is interpreting "BYDAY=1TH" as the first TH each year.