jjzjj

iphone - predicateForEventsWithStartDate 不起作用

coder 2024-01-15 原文

我正在尝试从日历中获取事件,并且我正在使用此方法进行操作:

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 为 nil,如果我使用:

[NSDate date]

找到我从今天到 future 的事件,而不是旧日期不起作用,我也尝试过其他旧日期,但数组总是零...

最佳答案

当使用 predicateForEventsWithStartDate 函数时,看起来返回的事件位于大约 4 年 (86400*365*4+86400*2) 的时间间隔内。 似乎是一个错误。

关于iphone - predicateForEventsWithStartDate 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13793284/

有关iphone - predicateForEventsWithStartDate 不起作用的更多相关文章

随机推荐