以下代码有效并从 iPhone 日历数据库中删除所有日历事件。但事件删除速度非常慢:iPhone 3GS 上每秒 2 个事件。因此,如果您有 3000 个事件 - 那么擦除它们需要 25 分钟...您将如何优化此代码?也许我做错了什么?谢谢。
- (void)deleteAllCalendarEventsFromIPhone:(NSError **)error {
EKEventStore *store = [[EKEventStore alloc] init];
NSUInteger beginYear = 1900;
NSUInteger endYear = 2100;
while (beginYear < endYear) {
NSPredicate *predicate =
[store predicateForEventsWithStartDate:[self createDateWithYear:beginYear month:1 day:1]
endDate:[self createDateWithYear:beginYear + 4 month:1 day:1]
calendars:nil];
NSArray *eventList = [store eventsMatchingPredicate:predicate];
for (EKEvent *event in eventList) {
success = [store removeEvent:event span:EKSpanThisEvent error:nil];
}
beginYear += 4;
}
[store release];
}