predicateForEventsWithStartDate:endDate:calendars: regression in iOS 6
| Originator: | syncluz | ||
| Number: | rdar://12671261 | Date Originated: | 2012-11-09 |
| Status: | Open | Resolved: | |
| Product: | iPhone/iPod touch | Product Version: | iOS 6 |
| Classification: | important | Reproducible: | Always |
Summary:
using EventKit's eventsMatchingPredicate: and predicateForEventsWithStartDate:endDate:calendars: does not return last day of multi-day, non-allday events.
Steps to Reproduce:
1) Create a multi-day event in calendar, for example Fri Nov. 9th, 6PM to Sun Nov. 11th, 7PM.
2) Run a eventsMatchingPredicate: query on the calendar for the last day of the event, i.e. from Sun Nov. 11th, 12AM to Mon Nov. 12th 12AM.
EKEventStore *ekEventStore = [[EKEventStore alloc] init];
NSPredicate *predicate = [ekEventStore
predicateForEventsWithStartDate:aFromDate
endDate:aToDate
calendars:nil // all calendars
];
// Fetch all events that match the predicate.
NSArray *events = [ekEventStore eventsMatchingPredicate:predicate];
Expected Results:
events array should contain the test event, as it overlaps the queried date range.
Actual Results:
events array does NOT contain the test event.
Regression:
this has worked correctly on iOS 5 and before.
Notes:
1) The bug is in the actual device as well as in the Simulator, and consistently for both only in iOS6. With iOS5, it works on both actual devices as well as the Simulator.
2) The bug does NOT affect multi-day allday events. Only multi-day timed events are affected.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Possible workaround
I'm using this predicate to get events for a single day, and use startDate at 0:00 AM of the day and endDate at 12:59:59 PM of the day.
If I make my startDate one second earlier ([startDate dateByAddingTimeInterval:-1]) I do get the affected events back. I then just need to filter out events that actually ended the day before:
NSArray *unsortedEvents = [eventStore eventsMatchingPredicate:predicate];
NSPredicate removePreviousDaysEvents = [NSPredicate predicateWithFormat:@"endDate > %@", [startDate dateByAddingTimeInterval:1]]; NSArray filteredEvents = [unsortedEvents filteredArrayUsingPredicate:removePreviousDaysEvents];