0

我正在尝试在日历上创建一个重复事件。我创建了一个 EKRecurrenceRule 并将其设置为该事件。但是该事件不是根据我的重复规则创建的。

这是我的代码,

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

使用此代码,事件仅在 6 月的每个第一个星期四创建,为什么会跳过 7 月?
请让我知道为什么没有根据我设置的重复规则创建事件。

4

1 回答 1

0

好的。在文档EKRecurrenceDayOfWeek Class Reference中,它说

一周中的一天可以选择有一个周数,指示重复规则频率中的特定日期。例如,星期几的日期值为星期二,周数为 2,在每月重复规则中表示每个月的第二个星期二,在每年重复规则中表示每年的第二个星期二。周数为 0 的一周中的某一天会忽略其周数。

您每年都在做频率,因此它将“BYDAY=1TH”解释为每年的第一个 TH。

于 2013-09-07T04:48:12.430 回答