gpt4 book ai didi

ekevent - 如何获取 future 日期的特定循环 EKEvent?

转载 作者:行者123 更新时间:2023-12-02 13:06:53 26 4
gpt4 key购买 nike

我将周期性事件 (EKEvent) 写入日历中。如何获取并修改特定日期内的这些重复事件之一?

事件是通过以下代码创建的:

+ (void) writeTestEvent{

EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];

event.calendar = [eventStore defaultCalendarForNewEvents];
event.title = @"Hello World!";
event.startDate = [NSDate date];
event.endDate = [NSDate date];

EKRecurrenceRule *recurrenceRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval:1 end:nil];
[event addRecurrenceRule:recurrenceRule];

[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
BOOL isSaved = [eventStore saveEvent:event span:EKSpanFutureEvents commit:YES error:&error];
NSLog(@"isSaved: (%d) with error: %@", isSaved, error);
} else {
NSLog(@"not granted with error: %@", error);
}
}];
}

使用 -predicateForEventsWithStartDate:endDate:calendars: 仅获取日期范围内的事件,而不是特定事件。使用事件标识符只能获取一个事件,但不能获取具体日期。

最佳答案

根据documentation :

Recurring event identifiers are the same for all occurrences. If you wish to differentiate between occurrences, you may want to use the start date.

获取 EKEvent 特定重复发生的示例:

EKEventStore *eventStore = [[EKEventStore alloc] init];

NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendars];

NSArray *results = [eventStore eventsMatchingPredicate:predicate];
for (int i = 0; i < results.count; i++) {
EKEvent *event = [results objectAtIndex:i]
if ([event. eventIdentifier isEqualToString: eventIdentifier]) {
// Match!!
break;
}
}

关于ekevent - 如何获取 future 日期的特定循环 EKEvent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19176709/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com