我正在创建能够将事件添加到iPhone日历中的简单应用程序。所以我正在玩EKEvent的recurrenceRule。有一个EKRecurrenceRule类,它有很长的构造函数:
(id)initRecurrenceWithFrequency:(EKRecurrenceFrequency)
typeinterval:(NSInteger)interval
daysOfTheWeek:(NSArray *)days
daysOfTheMonth:(NSArray *)monthDays
monthsOfTheYear:(NSArray *)months
weeksOfTheYear:(NSArray *)weeksOfTheYear
daysOfTheYear:(NSArray*)daysOfTheYear
setPositions:(NSArray *)setPositions
end:(EKRecurrenceEnd*)end
例如,如果我试图创建一个将在一周中的每个工作日重复的事件(星期日除外),我将使用此init:
initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily
interval:1
daysOfTheWeek:[NSArray arrayWithObjects:
[EKRecurrenceDayOfWeek dayOfWeek:2],
[EKRecurrenceDayOfWeek dayOfWeek:3],
[EKRecurrenceDayOfWeek dayOfWeek:4],
[EKRecurrenceDayOfWeek dayOfWeek:5],
[EKRecurrenceDayOfWeek dayOfWeek:6],
[EKRecurrenceDayOfWeek dayOfWeek:7], nil]
daysOfTheMonth:nil
monthsOfTheYear:nil
weeksOfTheYear:nil
daysOfTheYear:nil
setPositions:nil
end:nil
但它没有用,它只是每天重复一次事件:S 当我尝试使用EKRecurrenceFrequencyMonthly时,它就可以了。它每个月都会重复一次,但不会在周日重复。我向Apple报告了错误,因为它似乎有一个错误。
或者您有其他想法?
答案 0 :(得分:4)
Creating A Complex Recurrence Rule
“星期几。对于除日常重复规则之外的所有重复规则,您可以提供一组EKRecurrenceDayOfWeek对象,这些对象指示事件发生的星期几。 例如,您可以提供一个包含EKRecurrenceDayOfWeek对象的数组,其中包含周日值EKTuesday和EKFriday,以创建每周二和周五发生的重复。“
换句话说,你想要做的是使用星期一到星期五,然后再重复一周。每天周一至周五重复是没有意义的。
答案 1 :(得分:0)
Apple文档说:
@method initRecurrenceWithFrequency:interval:daysOfTheWeek:daysOfTheMonth:monthsOfTheYear:weeksOfTheYear:daysOfTheYear:setPositions:end:
@abstract指定的初始化程序。
@discussion这可用于构建任何类型的重复规则。但要注意某些组合毫无意义,将被忽略。例如,如果您将daysOfTheWeek传递给每日重复,则会忽略它们。
我想,我们不能每天说出来,也不要在星期天说。如果我弄错了,请告诉我。
感谢。
答案 2 :(得分:0)
initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily
interval:1
daysOfTheWeek:[NSArray arrayWithObjects:
[EKRecurrenceDayOfWeek dayOfWeek:2],
[EKRecurrenceDayOfWeek dayOfWeek:3],
[EKRecurrenceDayOfWeek dayOfWeek:4],
[EKRecurrenceDayOfWeek dayOfWeek:5],
[EKRecurrenceDayOfWeek dayOfWeek:6],
[EKRecurrenceDayOfWeek dayOfWeek:7], nil]
daysOfTheMonth:nil
monthsOfTheYear:nil
weeksOfTheYear:nil
daysOfTheYear:nil
setPositions:nil
end:nil
在此代码中,您使用EKRecurrenceFrequencyDaily
并再次指定一周的日期。而不是尝试使用EKRecurrenceFrequencyWeekly
EKRecurrenceDayOfWeek *weekReferecne=[[EKRecurrenceDayOfWeek alloc]initWithDayOfTheWeek:2 weekNumber:0];
并创建周数为0(零)的EKRecurrenceDayOfWeek
个对象,以便EKAlarm每天重复,直到您指定enddate为止。此代码有效。有一个快乐的编码