2013-08-22 35 views
0

我正試圖在日曆上創建重複事件。我創建了一個EKRecurrenceRule並將其設置爲該事件。但事件不是根據我的重複規則創建的。根據EKRecurrenceRule不添加EKEvent

這裏是我的代碼,

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

有了這個代碼的事件正在只能在每月的月1日的每個星期四,爲什麼被跳過7月設立的?
請讓我知道爲什麼事件不是根據我設置的重複規則創建的。

回答

0

好的。在該文件中EKRecurrenceDayOfWeek Class Reference,它說

一週中的一天可以有一個星期數,說明覆發規則的頻率特定的一天。例如,星期幾值爲星期二,星期數爲2的星期幾將表示每月重複規則中每月的第二個星期二以及每年重複規則中每年的第二個星期二。星期數爲0的星期幾將忽略其星期數。

您每年都在做頻率,所以它將每年的第一個TH解釋爲「BYDAY = 1TH」。