簡體   English   中英

EkEvent每天都在顯示

[英]EkEvent is showing on each day

我正在使用此代碼將事件添加到設備,但是在日歷中的設備上,它會在每個日期顯示,直到事件的結束日期

NSString *GoalDate =  [[[DFDateFormatterFactory sharedFactory] 
dateFormatterWithFormat:@"yyyy-MM-dd" andLocaleIdentifier:@"en_US"]

stringFromDate:self.datepicker.date];

        [AppHelper saveToUserDefaults:GoalDate withKey:@"goalsdates"];

        NSInteger dummyInteger = [[AppHelper userDefaultsForKey:@"event"]intValue];

        if(dummyInteger!=0)
        {

        [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
         {
        if (!granted)
        { return;
        }
    EKRecurrenceEnd *endRecurrence = nil;

   endRecurrence = [EKRecurrenceEnd recurrenceEndWithEndDate:self.datepicker.date];

   EKRecurrenceRule *recurrence;

 if(dummyInteger==1)
 {
 recurrence= [[EKRecurrenceRule alloc] initRecurrenceWithFrequency: EKRecurrenceFrequencyDaily
 interval:1 daysOfTheWeek:nil daysOfTheMonth:nil  monthsOfTheYear:nil   weeksOfTheYear:nil  daysOfTheYear:nil setPositions:nil  end:endRecurrence];

 }

    if(dummyInteger==2)
    {

    recurrence = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency: EKRecurrenceFrequencyWeekly  interval:7 daysOfTheWeek:nil daysOfTheMonth:nil  monthsOfTheYear:nil   weeksOfTheYear:nil  daysOfTheYear:nil setPositions:nil  
end:endRecurrence];

    }


             if(dummyInteger==3)
             {

recurrence = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency: EKRecurrenceFrequencyWeekly interval:1 daysOfTheWeek:nil daysOfTheMonth:nil  monthsOfTheYear:nil   weeksOfTheYear:nil  daysOfTheYear:nil setPositions:nil  end:endRecurrence];

            }

             if(dummyInteger==4)
             {


 recurrence = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency: EKRecurrenceFrequencyYearly  interval:1 daysOfTheWeek:nil daysOfTheMonth:nil  monthsOfTheYear:nil   weeksOfTheYear:nil  daysOfTheYear:nil setPositions:nil  end:endRecurrence];
                              }



        EKEvent *event = [EKEvent eventWithEventStore:store];

        event.title = [AppHelper userDefaultsForKey:@"nameofagoal"];

             event.allDay = false;

             event.startDate =[NSDate date];

     //  event.endDate = [event.startDate dateByAddingTimeInterval:60*60*24*7];  //set 1 hour meeting

             event.endDate =  self.datepicker.date;




       // event.endDate = endDate;
        [event setCalendar:[store defaultCalendarForNewEvents]];

        NSError *err = nil;

        [event addRecurrenceRule: recurrence];      

        [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];

        savedEventId = event.eventIdentifier;  //this is so you can access this event later
    }];

默認情況下,事件工具包會添加從開始到結束日期的事件。 如果您的開始日期和結束日期不同。 然后它將顯示從頭到尾的所有日子。 如果您只想在活動的開始日期和結束日期顯示活動,則必須添加兩個名稱相同但結束日期不同的活動。

您還可以將事件的allDay屬性設置為YES。 在這種情況下,如果您使用日歷的日視圖,則事件不會覆蓋整個屏幕。

暫無
暫無

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

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