EKEvents未来事件无效

时间:2016-02-24 10:11:58

标签: ios objective-c ekevent ekeventkit

这里我列出了所有日历活动,但没有显示2017年的活动,我知道只有4年以上的详细信息,但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);

1 个答案:

答案 0 :(得分:0)

虽然没有记录,但predicateForEventsWithStartDate:endDate:calendars:方法仅考虑从开始日期起4年内发生的事件。

PS:请不要那样做日期数学-1 * 60 * 60 * 24 * 365 * 4NSCalendarNSDateComponents提供了更强大,更精确的方法。