i facing strange issue "failed scene-update in time". after downloading data, storing in core data. if application in foreground, work fine. getting crash if switch app between states, background , foreground continuously while storing data in core data in process. crash not happen in debug mode.
i tried putting logs in different stages of core data operation method , found point app crashes actually. ui, using following code
databasemanagerclass *database = [[databasemanagerclass alloc]init]; [database deletedatafromformtable:nil]; [database insertdatainchecklisttable:[self.responsedictionary valueforkey:@"checklists"]]; [self performselectoronmainthread:@selector(mainthreadtask) withobject:nil waituntildone:yes];` the crash happening inside method "insertdatainchecklisttable". checked thread in insertdatainchecklisttable working. in main thread only. can give suggestion resolve issue.
thanks in advance, sree.
the updated code perform block
-(void)insertdatainformcolumnstable:(nsmutablearray*)responsearray withform:(form*)form { appdelegate objappdelegate = (appdelegate)[[uiapplication sharedapplication] delegate];
nsmanagedobjectcontext *moc = [objappdelegate managedobjectcontext]; nsmanagedobjectcontext *bgmoc = [[nsmanagedobjectcontext alloc] initwithconcurrencytype:nsprivatequeueconcurrencytype]; [bgmoc performblock:^{ (int count=0; count<[responsearray count]; count++) { nsdictionary *columndict = [responsearray objectatindex:count]; form_column *formcolumn = [nsentitydescription insertnewobjectforentityforname:@"form_column" inmanagedobjectcontext:moc]; if ([columndict valueforkey:formula]!=[nsnull null]) //added mritunjay formcolumn.formula = [columndict valueforkey:formula]; else formcolumn.formula=nil; if ([columndict valueforkey:asp_editable]!=[nsnull null]) formcolumn.asp_editable = [columndict valueforkey:asp_editable]; else formcolumn.asp_editable=nil; if ([columndict valueforkey:cm_editable]!=[nsnull null]) formcolumn.cm_editable = [columndict valueforkey:cm_editable]; else formcolumn.cm_editable=nil; if ([columndict valueforkey:im_editable]!=[nsnull null]) formcolumn.im_editable = [columndict valueforkey:im_editable]; else formcolumn.im_editable=nil; if ([columndict valueforkey:sp_editable]!=[nsnull null]) formcolumn.sp_editable = [columndict valueforkey:sp_editable]; else formcolumn.sp_editable=nil; if ([columndict valueforkey:asp_editable]!=[nsnull null]) formcolumn.dialog_row = [columndict valueforkey:asp_editable]; else formcolumn.dialog_row=nil; if ([columndict valueforkey:index]!=[nsnull null]) formcolumn.index = [columndict valueforkey:index]; else formcolumn.index=nil; if ([columndict valueforkey:web_only]!=[nsnull null]) formcolumn.web_only = [columndict valueforkey:web_only]; else formcolumn.web_only=nil; if ([columndict valueforkey:label]!=[nsnull null]) formcolumn.label = [columndict valueforkey:label]; else formcolumn.label=nil; formcolumn.form_id = form.form_id; if ([columndict valueforkey:id]!=[nsnull null]) formcolumn.column_id=[columndict valueforkey:id]; else formcolumn.column_id=nil; if ([columndict valueforkey:type]!=[nsnull null]) formcolumn.type=[columndict valueforkey:type]; else formcolumn.type=nil; nsarray *selectionarray = [columndict valueforkey:selections]; if ([selectionarray count]) { (int count = 0; count < [selectionarray count]; count++) { form_sub_columns *formsubcolumns = [nsentitydescription insertnewobjectforentityforname:@"form_sub_columns" inmanagedobjectcontext:moc]; nsdictionary *subcolumndict = [selectionarray objectatindex:count]; if ([subcolumndict valueforkey:id]!=[nsnull null]) formsubcolumns.column_id=[subcolumndict valueforkey:id]; else formsubcolumns.column_id=nil; if ([subcolumndict valueforkey:label]!=[nsnull null]) formsubcolumns.label=[subcolumndict valueforkey:label]; else formsubcolumns.label=nil; if ([subcolumndict valueforkey:requires_remarks]!=[nsnull null]) formsubcolumns.requires_remarks=[subcolumndict valueforkey:requires_remarks]; else formsubcolumns.requires_remarks=nil; if ([subcolumndict valueforkey:value]!=[nsnull null]) formsubcolumns.value=[subcolumndict valueforkey:value]; else formsubcolumns.value=nil; if ([subcolumndict valueforkey:description]!=[nsnull null]) formsubcolumns.description_name=[subcolumndict valueforkey:description]; else formsubcolumns.description_name=nil; if ([subcolumndict valueforkey:selection_type_id]!=[nsnull null]) formsubcolumns.selection_type_id=[subcolumndict valueforkey:selection_type_id]; else formsubcolumns.value=nil; [formcolumn addsun_columnsobject:formsubcolumns]; } } [formcolumn addformobject:form]; [form addcolumnsobject:formcolumn]; } if([form.enable_attachment boolvalue]) { form_column *formcolumn = [nsentitydescription insertnewobjectforentityforname:@"form_column" inmanagedobjectcontext:moc]; formcolumn.label = @"add attachments"; formcolumn.form_id = form.form_id; formcolumn.index = [nsnumber numberwithint:998]; formcolumn.column_id=[nsnumber numberwithint:998]; // hardcoded if attachment enabled. formcolumn.web_only = [nsnumber numberwithint:0]; formcolumn.type=[nsnumber numberwithint:-1]; [form addcolumnsobject:formcolumn]; } if ([[nsthread currentthread] ismainthread]) { nslog(@"main thread inside block"); } else { nslog(@"not main thread inside block"); } nserror *error; if(![bgmoc save:&error]){ nslog(@"error %@", [error localizeddescription]); } }]; }
processing data on main/ui thread always bad idea , causes issues this.
your -insertdataintochecklisttable needs run on background queue means should be:
- creating second
nsmanagedobjectcontextnsprivatequeueconcurrencytype - associating main context
- using
-performblock:process data againstnsmanagedobjectcontext - saving when processing complete
that data processing off main queue. never, ever process data on main queue.
Comments
Post a Comment