开发者

EKRecurrenceRule for working days in a week

I am creating simple application that has ability to add events into iPhone Calendar. So I am playing with EKEvent's recurrenceRule. There is a class EKRecurrenceRule with very long constructor:

(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

So for example, if I am trying to create a event that will be repeated every work day in the week (except Sunday), I will use this init:

initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily 
                   interval:1 
              daysOfTheWeek:[NSArray arrayWithObjects:
                                [EKRecurrenceDayOfWeek dayOfWeek:2],
                                [EKRecurrenceDayOfWeek dayOfWeek:3],
                                [EKRecurrenceDayOfWeek dayO开发者_高级运维fWeek:4],
                                [EKRecurrenceDayOfWeek dayOfWeek:5], 
                                [EKRecurrenceDayOfWeek dayOfWeek:6],
                                [EKRecurrenceDayOfWeek dayOfWeek:7], nil] 
            daysOfTheMonth:nil 
           monthsOfTheYear:nil 
            weeksOfTheYear:nil 
             daysOfTheYear:nil 
              setPositions:nil 
                       end:nil

but it is not working, it just repeat event every day :S When I try use EKRecurrenceFrequencyMonthly, then it works. It repeats event every month, but not on Sunday. I reported bug to Apple, because it seems that they have a bug.

Or you have other idea?


Creating A Complex Recurrence Rule

"Days of the week. For all recurrence rules besides daily recurrence rules, you can provide an array of EKRecurrenceDayOfWeek objects that indicate the days of the week on which the event occurs. For example, you can provide an array containing EKRecurrenceDayOfWeek objects with day of week values of EKTuesday and EKFriday to create a recurrence that occurs every Tuesday and Friday."

In other words, what you want to do is use Monday to Friday and then repeat that WEEKLY. Repeating Monday to Friday every day makes no sense.


Apple documentation says:

@method initRecurrenceWithFrequency:interval:daysOfTheWeek:daysOfTheMonth:monthsOfTheYear:weeksOfTheYear:daysOfTheYear:setPositions:end:

@abstract The designated initializer.

@discussion This can be used to build any kind of recurrence rule. But be aware that certain combinations make no sense and will be ignored. For example, if you pass daysOfTheWeek for a daily recurrence, they will be ignored.

I think, we can't say it daily and say not on Sunday. Please let me know if I am mistaken.

Thanks.


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

In this code you are using EKRecurrenceFrequencyDaily and again specifying the days of a week. Instead of this try to execute with EKRecurrenceFrequencyWeekly

EKRecurrenceDayOfWeek *weekReferecne=[[EKRecurrenceDayOfWeek alloc]initWithDayOfTheWeek:2 weekNumber:0];

and create EKRecurrenceDayOfWeek objects with week number 0(zero) so that the EKAlarm repeats every day until you specify the enddate.. This code works. Have a Happy coding

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜