我正在尝试从日历中获取事件,并且正在使用此方法进行操作:
predicateForEventsWithStartDate:endDate:calendars:
但如果我创建这样的开始日期:
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];
然后我这样做:
predicate = [eventStore predicateForEventsWithStartDate:date endDate:endDate calendars: [eventStore calendarsForEntityType:EKEntityTypeEvent]];
NSArray *eventArray = [eventStore eventsMatchingPredicate:predicate];
eventArray 为零,而不是如果我使用:
[NSDate date]
找到我从今天到未来的事件,而不是旧日期不起作用,我也尝试过其他旧日期,但数组总是为零......