iOS7 - 设备500个复制记录时与提交到eventstore restaring = YES(

2019-10-18 20:41发布

下面的代码将正常工作与500分的记录,我们分批操作,加入500个记录后提交eventstore。

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];

假设我们需要为未来修改每个复制事件记录的eventidentifier,那么我们就应该提交每个记录,以获得标识符。 但这样做,我们越来越内存警告和设备正在重新启动..以下时是示例代码:

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);

    }

}

我们需要为未来的修改(更新/删除)eventidentifier,因此寻找一种方式通过gettng其eventidentifier插入500+记录到eventstore。 任何帮助将不胜感激。 谢谢。

文章来源: iOS7 - device restaring when copying 500 records to eventstore with Commit=YES