0

Here i am listing all events from calendar but it not displaying 2017 events, i know only 4 years above details fetching but there are no record getting from 2017

EKEventStore *store = [[EKEventStore alloc] init]; [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
            NSLog(@"acces to §Reminder granded %i ",granted);
            [parser parse];

        }];

        NSDate* startDate =  [NSDate dateWithTimeIntervalSinceNow:-1 * 60 * 60 * 24 * 365 * 4];
        NSDate* endDate =  [NSDate dateWithTimeIntervalSinceNow:[[NSDate distantFuture] timeIntervalSinceReferenceDate]];

        NSPredicate *fetchCalendarEvents = [store predicateForEventsWithStartDate:startDate endDate:endDate calendars:nil];

        eventList = [store eventsMatchingPredicate:fetchCalendarEvents];
        calanderDict =[[NSMutableDictionary alloc]init];

        for(int i=0; i < eventList.count; i++){

            NSLog(@"Event Title:%@", [[eventList objectAtIndex:i] title]);
            NSLog(@"Event StartDate:%@", [[eventList objectAtIndex:i] startDate]);
            NSLog(@"Event EndDate:%@", [[eventList objectAtIndex:i] endDate]);
            //    NSLog(@"Event Notes:%@", [[eventList objectAtIndex:i]notes]);
            NSLog(@"Event Identifier:%@", [[eventList objectAtIndex:i] calendarItemIdentifier]);

            [calanderDict setObject:[[eventList objectAtIndex:i] title] forKey:@"Title"];
            [calanderDict setObject:[[eventList objectAtIndex:i] startDate] forKey:@"Creation_date"];
            [calanderDict setObject:[[eventList objectAtIndex:i] endDate] forKey:@"End_date"];
            [calanderDict setObject:[[eventList objectAtIndex:i]calendarItemIdentifier] forKey:@"Identifier"];
            [calList addObject:[calanderDict copy]];
        }
        NSLog(@"Cal List %@",calList);
Vivek Goswami
  • 432
  • 3
  • 16

1 Answers1

0

Although it's not documented, the method predicateForEventsWithStartDate:endDate:calendars: considers only events within 4 years in the future from the start date.

PS: Please don't do date math that way -1 * 60 * 60 * 24 * 365 * 4. NSCalendar and NSDateComponents provide more powerful and precise methods to do that.

vadian
  • 274,689
  • 30
  • 353
  • 361