According to this answer and this post, EKEventStore eventsMatchingPredicate:
doesn't support predicates with a startDate
and endDate
more than four years apart. I can't find any official documentation on this fact, but in practice the method appears to just return events up to endDate
or four years after startDate
, whichever comes first.
[NSDate distantPast]
returns a date centuries in the past, so you're all but guaranteed to get a wrong answer if you create a predicate with that as your start date.
The simplest solution would be to change your code to something like this:
NSDate* fourYearsAgo = [NSDate dateWithTimeIntervalSinceNow:-1 * 60 * 60 * 24 * 365 * 4];
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:fourYearsAgo endDate:[NSDate date] calendars:@[cal]];
If this doesn't work for you, you'll either have to find a way to choose your bounds more wisely or create successive four-year predicates until you find what you're looking for.