Iphone EKRecurrenceRule-添加重复事件,但不包括周末

Iphone EKRecurrenceRule-添加重复事件,但不包括周末,iphone,ekeventkit,Iphone,Ekeventkit,我有一个方法,可以将事件添加到本机iphone日历中。 它已经成功地添加了每月提醒,但我想强制所有每月提醒都归入周(而不是周末) NSDictionary模型非常简单 身份证件: 开始日期 完成日期 付款间隔期=每月 - (void)addRecurringEventsForPartnership:(NSDictionary *)dict{ ENTER_METHOD; NSError *error = nil; EKEvent *startEvent = [EKEve

我有一个方法,可以将事件添加到本机iphone日历中。 它已经成功地添加了每月提醒,但我想强制所有每月提醒都归入周(而不是周末)

NSDictionary模型非常简单 身份证件: 开始日期 完成日期 付款间隔期=每月

- (void)addRecurringEventsForPartnership:(NSDictionary *)dict{
    ENTER_METHOD;

    NSError *error = nil;
    EKEvent *startEvent  = [EKEvent eventWithEventStore:self.eventStore];
    startEvent.calendar = self.defaultCalendar;
     startEvent.availability = EKEventAvailabilityFree;
    startEvent.startDate = [NSDate dateWithLongFormatString:[dict valueForKey:@"Start_Date__c"]];
    startEvent.allDay = YES;
   // startEvent.endDate =  [startEvent.startDate dateByAddingTimeInterval:30*60];
     startEvent.title = [dict theNameValue];
    //http://stackoverflow.com/questions/7718006/xcode-why-is-my-event-not-being-added-to-the-calendar
    if ([startEvent.startDate isEqualToDate:startEvent.endDate]) {
        startEvent.endDate = [startEvent.startDate dateByAddingTimeInterval:30*60];;
    }

   // if 
    if ([[dict valueForKey:@"Payment_Interval__c"] isEqualToString:@"Monthly"]) {
        EKRecurrenceFrequency freq = EKRecurrenceFrequencyMonthly;
        int recurrenceInterval = 1;

        EKRecurrenceRule *rule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:freq interval:recurrenceInterval end:nil];
        startEvent.recurrenceRule = rule;

        startEvent.notes = [NSString stringWithFormat:@"Id:%@",[dict valueForKey:@"Id"]];
        // [self.eventStore removeEvent:startEvent span:EKSpanThisEvent error:&error];
        [self.eventStore saveEvent:startEvent span:EKSpanThisEvent error:&error];

        if (error != nil)
        {
            DLog(@"WARNING:%@",error.description);
            // TODO: error handling here
        }
    }



  //  DLog(@"startEvent.endDate:%@",startEvent.endDate);


    EKEvent *finishEvent  = [EKEvent eventWithEventStore:self.eventStore];
    finishEvent.calendar = self.defaultCalendar;
    finishEvent.availability = EKEventAvailabilityFree;
    finishEvent.startDate = [NSDate dateWithLongFormatString:[dict valueForKey:@"Finish_Date__c"]];
    finishEvent.allDay = YES;
    finishEvent.title = [NSString stringWithFormat:@"%@ - Finish",[dict theNameValue]];


    finishEvent.notes = [NSString stringWithFormat:@"Id:%@",[dict valueForKey:@"Id"]];
    [self.eventStore saveEvent:finishEvent span:EKSpanThisEvent error:&error];

    if (error != nil)
    {
        DLog(@"WARNING:%@",error.description);
        // TODO: error handling here
    }

}

您是否可以使用
NSDateFormatter
获取一周中的数字日期,然后根据返回的日期减去或添加1或2进行调整

[dateFormatter setDateFormat:@"c"];

将返回一周中的数字(1-7)天,我相信这里有一些有用的东西(至少在iOS7中,没有在其他系统上测试):


你有什么有效的解决办法吗?我一直在尝试编辑每月的重复周期,但只针对一天,而一天的其余时间将在同一时间发生。如何实现?
EKRecurrenceRule *er = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyMonthly interval:1
                                                                   daysOfTheWeek:@[[EKRecurrenceDayOfWeek dayOfWeek:2], // Monday
                                                                                   [EKRecurrenceDayOfWeek dayOfWeek:3], // Tuesday
                                                                                   [EKRecurrenceDayOfWeek dayOfWeek:4], // Wednesday
                                                                                   [EKRecurrenceDayOfWeek dayOfWeek:5], // Thursday
                                                                                   [EKRecurrenceDayOfWeek dayOfWeek:6]] // Friday
                                                                  daysOfTheMonth:@[@1, @2]
                                                                 monthsOfTheYear:nil weeksOfTheYear:nil daysOfTheYear:nil setPositions:nil end:nil];
event.recurrenceRules = @[er];