predicateForEventsWithStartDate:endDate:calendars:EKEventStore不起作用 [英] predicateForEventsWithStartDate:endDate:calendars: EKEventStore doesn't work
问题描述
我已在以下日期范围的EKCalendar中保存了28个EKEvent:2012-01-01和2013-01-18,EKEvent已全部存储,我可以在iCloud的iOS日历中看到它,然后我想检索所有此EKEvent的范围为2012-01-01和2013-01-18,我使用EKEventStore的此方法:
i have saved 28 EKEvent in a EKCalendar in this range date: 2012-01-01 and 2013-01-18, the EKEvent are all stored and i can see it in the iOS Calendar on iCloud, then i want retrieve all this EKEvent in the range 2012-01-01 and 2013-01-18 and i use this method of EKEventStore:
predicateForEventsWithStartDate:endDate:calendars:
这是要在日历中获取事件的NSPredicate,我通过了起始日期2012-01-01和endDate:2013-01-18,因此返回给我EKEvent的数组只有8个元素,所以我的问题为什么找不到我全部28个事件?我错了吗?
that is a NSPredicate to fetch event in the calendar, i pass with start date 2012-01-01 and with endDate:2013-01-18 so the array that return me with the EKEvent have only 8 element, so my question is why it doesn't find me all 28 event? what i wrong?
这是我使用的完整代码:
this is the complete code i use:
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的日期,然后执行此操作:
then i use the same code for create the 2013-01-18 date that is the endDate, then i do this:
EKEventStore *eventStore = [[EKEventStore alloc] init];
NSPredicate *predicateEvent = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:[eventStore calendarsForEntityType:EKEntityTypeEvent]];
NSArray *eventArray = [eventStore eventsMatchingPredicate:predicateEvent];
eventArray仅包含8个元素...其他20个元素在哪里?请让我发疯,有人可以帮助我吗?
the eventArray contains only 8 elements...and where are the other 20? please i'm going crazy someone can help me?
推荐答案
在设备上,转到:Settings > Mail, Contacts, Calendars
,然后在Calendars
子部分下转到Sync > All Events
.不仅是过去30天,60天之内的事件,等等.
On your device, go to: Settings > Mail, Contacts, Calendars
, and under the Calendars
sub-section go to Sync > All Events
. Not just events from the past 30, 60 days, etc.
这篇关于predicateForEventsWithStartDate:endDate:calendars:EKEventStore不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!