ios - applicationDidEnterBackground is not waiting till method execution is completed -
ios - applicationDidEnterBackground is not waiting till method execution is completed -
i save info when app goes in background. doing cancelling nsoperation , saving info in applicationdidenterbackground
. not finish execution.
how can finish before app goes in background?
code :
-(void)applicationdidenterbackground:(uiapplication *)application { //function_start // utilize method release shared resources, save user data, invalidate timers, , store plenty application state info restore application current state in case terminated later. // if application supports background execution, method called instead of applicationwillterminate: when user quits. [self performselectoronmainthread:@selector(dispatchstatenotification:) withobject:[nsnumber numberwithint:666] waituntildone:yes ]; // write core info gwscoredatacontroller *datacontroller = [gwscoredatacontroller sharedmanager]; nserror *error; if (![datacontroller.managedobjectcontext save:&error]) { nslog(@"error while saving info core data: %@", [error localizeddescription]); } // function_end } -(void)dispatchstatenotification:(nsnumber *)value { [[nsnotificationcenter defaultcenter] postnotificationname:application_entered_background_notification object:value]; }
you can start background task, , cleanup stuff
- (void)applicationdidenterbackground { uibackgroundtaskidentifier bgtaskid = [[uiapplication sharedapplication] beginbackgroundtaskwithexpirationhandler:^{ [[uiapplication sharedapplication] endbackgroundtask:bgtaskid]; }]; // start cleanup ....... [[uiapplication sharedapplication] endbackgroundtask: bgtaskid]; }
ios iphone nsnotificationcenter nsoperation appdelegate
Comments
Post a Comment