问题
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:
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?
EDIT:
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];
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];
the eventArray contains only 8 elements...and where are the other 20? please i'm going crazy someone can help me?
回答1:
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.
来源:https://stackoverflow.com/questions/13812281/predicateforeventswithstartdateenddatecalendars-ekeventstore-doesnt-work