簡體   English   中英

EKEvent沒有遵循EKRecurrenceRule

[英]EKEvent is not following EKRecurrenceRule

我正在使用EventKit在iOS日歷中添加事件。 該事件是重復發生的事件。 我正在以編程方式為事件設置重復規則。 活動已成功添加到日歷中,但日歷上顯示的日期與我設置的日期不同。

活動詳情 在此處輸入圖片說明

重復規則。 在此處輸入圖片說明

將事件成功添加到日歷后,這就是我在日歷條目中看到的內容 在此處輸入圖片說明

我的活動正在2017年展出,但我沒有將結束日期設置為2017年,而是2016年。

我嘗試將事件與iOs日歷添加在一起,並得到了相同的結果。

下面是我正在使用的代碼。

/*!
 *  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);
    }
}

以下是我在調試器中獲得的事件詳細信息:

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);
};

請建議我使用的是錯誤的,或者我缺少什么。

我已經在這個答案的幫助下找到了這個問題的解決方案

iOS日歷表現異常

我以錯誤的方式設置Ends參數。 該日期應與開始日期相同。 時間應該不同。

現在我的活動屏幕看起來像這樣

在此處輸入圖片說明

希望有一天可以節省別人的時間

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM