首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >predicateForEventsWithStartDate:endDate:calendars: EKEventStore不工作

predicateForEventsWithStartDate:endDate:calendars: EKEventStore不工作
EN

Stack Overflow用户
提问于 2012-12-11 09:34:57
回答 1查看 962关注 0票数 1

我已经在此日期范围内的EKCalendar中保存了28个EKEvent : 2012-01-01和2013-01-18,这些EKEvent都已存储,我可以在iCloud上的iOS日历中看到它,然后我希望检索2012-01-01和2013-01-18范围内的所有EKEvent,并使用此EKEventStore方法:

代码语言:javascript
复制
predicateForEventsWithStartDate:endDate:calendars:

这是一个在日历中获取事件的NSPredicate,我传递了开始日期2012-01-01,结束日期:2013-01-18,所以用EKEvent返回的数组只有8个元素,所以我的问题是为什么它没有找到所有28个事件?我做错了什么?

编辑:

这是我使用的完整代码:

代码语言:javascript
复制
NSDate* sourceDate2 = [dateFormat dateFromString:@"2012/01/01"];


    NSTimeZone* sourceTimeZone2 = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    NSTimeZone* destinationTimeZone2 = [NSTimeZone systemTimeZone];

    NSInteger sourceGMTOffset2 = [sourceTimeZone2 secondsFromGMTForDate:sourceDate2];
    NSInteger destinationGMTOffset2 = [destinationTimeZone2 secondsFromGMTForDate:sourceDate2];
    NSTimeInterval interval2 = destinationGMTOffset2 - sourceGMTOffset2;

    NSDate* destinationDate2 = [[NSDate alloc] initWithTimeInterval:interval2 sinceDate:sourceDate2];

    NSTimeInterval time2 = floor([destinationDate2 timeIntervalSinceReferenceDate] / 86400.0) * 86400.0;

    NSDate *startDate = [NSDate dateWithTimeIntervalSinceReferenceDate:time2];

然后,我使用相同的代码来创建2013-01-18日期,也就是endDate,然后执行以下操作:

代码语言:javascript
复制
EKEventStore *eventStore = [[EKEventStore alloc] init];

NSPredicate *predicateEvent = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:[eventStore calendarsForEntityType:EKEntityTypeEvent]];

NSArray *eventArray = [eventStore eventsMatchingPredicate:predicateEvent];

eventArray只包含8个elements...and,其他20个在哪里?求求你,我要疯了,有人能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2013-01-25 02:35:13

在您的设备上,转到:Settings > Mail, Contacts, Calendars,然后在Calendars子部分下转到Sync > All Events。不只是过去30天、60天等的事件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13812281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档