EKEvents 的谓词未能初始化我的结束日期

Predicate for EKEvents failed to init my end date

我在 EKEvents 上遇到了一个获取请求。

根据 Apple 示例,我创建了两个日期,分别是现在 20 年前和未来 20 年。

NSDateComponents *twentyYearsAgoComponents = [[NSDateComponents alloc] init];
twentyYearsAgoComponents.year = -20;
NSDate *twentyYearsAgo = [[NSCalendar currentCalendar] dateByAddingComponents:twentyYearsAgoComponents
                                                                       toDate:[NSDate date]
                                                                      options:0];

// Create the end date components

NSDateComponents *twentyYearsFromNowComponents = [[NSDateComponents alloc] init];
twentyYearsFromNowComponents.year = 20;
NSDate *twentyYearsFromNow = [[NSCalendar currentCalendar] dateByAddingComponents:twentyYearsFromNowComponents
                                                                           toDate:[NSDate date]
                                                                          options:0];



NSPredicate *predicate = [self.eventStoreGD predicateForEventsWithStartDate:twentyYearsAgo endDate:twentyYearsFromNow calendars:@[self.calendarForEventGD]]; // nil = all calendars

NSLog(@"predicate : %@",predicate);

在控制台中,我打印了这个:

2015-04-10 14:52:52.825 ohmygoods[1658:270016] [dateFormatter stringFromDate:twentyYearsFromNow] : 2035-04-10
2015-04-10 14:53:06.120 ohmygoods[1658:270016] predicate : EKEventPredicate start:10/04/1995 14:51; end:10/04/1999 14:51; cals:(
"x-apple-eventkit:///Calendar/p11"

)

你看

end:10/04/1999 14:51

而不是 10/04/2035 ???

我找到了这个答案 here

您不能获取从开始日期算起超过 4 年的数据。 不要问为什么...