简体   繁体   中英

predicateForEventsWithStartDate doesn't work

i'm trying to fetch event from a calendar, and i'm doing it using this method:

predicateForEventsWithStartDate:endDate:calendars:

but if i create a start date like this:

NSString *str =@"3/15/1980 9:15 PM";
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"MM/dd/yyyy hh:mm a"];
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [formatter setTimeZone:gmt];
    NSDate *date = [formatter dateFromString:str];

then i do this:

predicate = [eventStore predicateForEventsWithStartDate:date endDate:endDate calendars:  [eventStore calendarsForEntityType:EKEntityTypeEvent]];

NSArray *eventArray = [eventStore eventsMatchingPredicate:predicate];

the eventArray is nil, instead if i use:

[NSDate date]

find me the events from today to the future, instead with the old date don't work, i have tried also other old date, but the array is always nil...

When using predicateForEventsWithStartDate function, it looks like the events returned lies in a time interval of around 4 years (86400*365*4+86400*2). Seems like a bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM