问题
The below code will work fine with 500 records, we are batching the operation and commit the eventstore after adding 500 records.
EKEventStore *eventStore = [[EKEventStore alloc] init];
for(int i=0 ; i< 500 ; i++){
EKCalendar *calendarDef = [eventStore defaultCalendarForNewEvents];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
[event setCalendar:calendarDef];
//set values to this event. like title, notes, startDate, endDate, location
event.title = [NSString stringWithFormat:@"testno-%i", i];
event.startDate = [NSDate date];
event.endDate = [[NSDate date] dateByAddingTimeInterval:180];
NSError *err1 = nil;
BOOL isStoredd = [eventStore saveEvent:event span:EKSpanThisEvent commit:NO error:&err1];
NSLog(@"item %i", i);
if(isStoredd){
NSLog(@"stored");
}else{
NSLog(@"event saved error = %@",err1);
}
}
[eventStore commit:NULL];
Suppose we need the eventidentifier of each copying event record for future modifications, then we should commit each record to get the identifier . But when doing this we are getting memory warning and device is restarting.. Below is the sample code:
EKEventStore *eventStore = [[EKEventStore alloc] init];
for(int i=0 ; i< 500 ; i++){
NSString *eventIde = nil;
EKCalendar *calendarDef = [eventStore defaultCalendarForNewEvents];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
[event setCalendar:calendarDef];
//set values to this event. like title, notes, startDate, endDate, location
event.title = [NSString stringWithFormat:@"testno-%i", i];
event.startDate = [NSDate date];
event.endDate = [[NSDate date] dateByAddingTimeInterval:180];
NSError *err1 = nil;
BOOL isStoredd = [eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&err1];
NSLog(@"item %i", i);
if(isStoredd){
eventIde = event.eventIdentifier;
//storing the eventIde to application's database to modify/delete the event later.
NSLog(@"stored identifier %@", eventIde);
}else{
NSLog(@"event saved error = %@",err1);
}
}
We need the eventidentifier for future modifications(update/delete), So looking for a way to insert 500+ records into eventstore by gettng its eventidentifier. Any help would be greatly appreciated. Thanks.
来源:https://stackoverflow.com/questions/19682807/ios7-device-restaring-when-copying-500-records-to-eventstore-with-commit-yes