简体   繁体   English

EKEvent没有遵循EKRecurrenceRule

[英]EKEvent is not following EKRecurrenceRule

I am adding an event in iOS calendar using EventKit . 我正在使用EventKit在iOS日历中添加事件。 The event is recurring event. 该事件是重复发生的事件。 I am setting recurring rules for the event programmatically. 我正在以编程方式为事件设置重复规则。 Event is getting added in calendar successfully but the dates shown on calendar are not same as I set them. 活动已成功添加到日历中,但日历上显示的日期与我设置的日期不同。

Event details 活动详情 在此处输入图片说明

Recurring rules. 重复规则。 在此处输入图片说明

After event is successfully added to calendar this is what I get in calendar entry 将事件成功添加到日历后,这就是我在日历条目中看到的内容 在此处输入图片说明

My event is being show for 2017 but I didn't set the end date to 2017 it was 2016. 我的活动正在2017年展出,但我没有将结束日期设置为2017年,而是2016年。

I tried adding the event with iOs calendar and got the same result. 我尝试将事件与iOs日历添加在一起,并得到了相同的结果。

Below is the code I am using. 下面是我正在使用的代码。

/*!
 *  This method, called added event to the calendar
 */
- (void)addEventToCalendar
{
    @try {


        /* Event added to device calendar */
        [SINGLETON.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
            if (granted) {

                [SINGLETON.event_Dateformat setDateFormat:[self dateFormatForSelectedLanguage]];
                EKEvent *event = [EKEvent eventWithEventStore:SINGLETON.eventStore];
                event.title = _event.eventTitle;
                event.startDate = [SINGLETON.event_Dateformat dateFromString:eventInfo.eventActualStartDate];
                event.endDate = [SINGLETON.event_Dateformat dateFromString:eventInfo.eventActualEndDate];
                event.notes = flattenHTML(eventInfo.eventDescription);

                // Get notification 2 hours before the event start time.
                [event addAlarm:[EKAlarm alarmWithRelativeOffset:-(2*60*60)]];
                [event setCalendar:[SINGLETON.eventStore defaultCalendarForNewEvents]];

                /* Here opening Event edit view controller */
                EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];
                controller.event = event;
                controller.eventStore = SINGLETON.eventStore;
                controller.editViewDelegate = self;

                // Event is recurring mark it is repeat in calendar.

                // List of days on which a particular event occurs.
                NSMutableArray <EKRecurrenceDayOfWeek *> *daysOfTheWeek = [[NSMutableArray alloc] init];

                if (_event.eventRecurrence &&
                    ! [_event.eventDays containsString:@"N/A"]) {
                    for (NSString *dayName in [_event.eventDays componentsSeparatedByString:@","]) {
                        EKRecurrenceDayOfWeek *aDay = [EKRecurrenceDayOfWeek dayOfWeek:[self weekDayForDayName:dayName]];
                        [daysOfTheWeek addObject:aDay];
                    }
                }

                // When to stop reminding user for the event.
                EKRecurrenceEnd *endDate = [EKRecurrenceEnd recurrenceEndWithEndDate:event.endDate];

                EKRecurrenceRule *repeatRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:[self recurrenceFrequencey:_event.eventType] interval:1 daysOfTheWeek:daysOfTheWeek daysOfTheMonth:nil monthsOfTheYear:nil weeksOfTheYear:nil daysOfTheYear:nil setPositions:nil end:endDate];

                event.allDay = NO;

                 event.recurrenceRules = @[repeatRule];

                //[event addRecurrenceRule:repeatRule];

                dispatch_async(dispatch_get_main_queue(), ^{

                    //NSError *erroOnSave = nil;
                    // [SINGLETON.eventStore saveEvent:event span:EKSpanFutureEvents commit:YES error:&erroOnSave];
                    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                    [self presentViewController:controller animated:YES completion:nil];
                });

            }else{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

                [SINGLETON alertViewTitle:@""
                                  message:NSLocalizedString(@"Calendar setting alert", nil)
                              cancelTitle:NSLocalizedString(@"OK", nil)
                                doneTitle:nil
                                      tag:0];
                    });

            }
        }];

    }
    @catch (NSException *exception) {
        DLog(@"%@",exception);
    }
}

Below is the event details I get in debugger: 以下是我在调试器中获得的事件详细信息:

EKEvent <0x7f94b1f19d00>
{
     EKEvent <0x7f94b1f19d00>
{    title =        TBW   ; 
     location =     ; 
     calendar =     EKCalendar <0x7f94b439d280> {title = Calendar; type = Local; allowsModify = YES; color = #1BADF8;}; 
     alarms =       (
    "EKAlarm <0x7f94b4352fe0> {triggerInterval = -7200.000000}"
); 
     URL =          (null); 
     lastModified = 2016-04-25 05:18:27 +0000; 
     startTimeZone =    Asia/Kolkata (GMT+5:30) offset 19800; 
     startTimeZone =    Asia/Kolkata (GMT+5:30) offset 19800 
}; 
     location =     ; 
     structuredLocation =   (null); 
     startDate =    2015-09-20 18:30:00 +0000; 
     endDate =      2016-05-31 18:30:00 +0000; 
     allDay =       0; 
     floating =     0; 
     recurrence =   EKRecurrenceRule <0x7f94b43e7110> RRULE FREQ=WEEKLY;INTERVAL=1;UNTIL=20160531T183000Z;BYDAY=MO,TH; 
     attendees =    (null); 
     travelTime =   (null); 
     startLocation =    (null);
};

Please suggest what I am using wrong or I am missing something. 请建议我使用的是错误的,或者我缺少什么。

I have found a solution of this question with help of this answer 我已经在这个答案的帮助下找到了这个问题的解决方案

iOS calendar is behaving strangly iOS日历表现异常

I was setting the Ends parameter in wrong way. 我以错误的方式设置Ends参数。 It should be on same date as Starts . 该日期应与开始日期相同。 Time should be different. 时间应该不同。

Now my event screen looks like this 现在我的活动屏幕看起来像这样

在此处输入图片说明

Hope this will save someone else's time someday 😃 😃 😃 😃 希望有一天可以节省别人的时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM