1 1, the project needs, is the program home key into the backstage, 3 minutes after exiting the landing,2 3 first, IOS will continue into the background, give us 5 seconds to process the relevant data, after 5 seconds, the program will no longer execute any code, in a suspended state. 4 5 6 7 8 9- (void) Applicationdidenterbackground: (UIApplication *) Application {Ten One //cut into the background, apply for background task time, A -UIApplication *app =[UIApplication sharedapplication]; - theUibackgroundtaskidentifier TaskID;//A background task identifier - -TaskID = [App beginbackgroundtaskwithexpirationhandler:^{//if the system feels that we are running too long, it will execute this block and stop running the application - + - + [app Endbackgroundtask:taskid]; A at }]; - - - - if(TaskID = = uibackgroundtaskinvalid) {//Uibackgroundtaskinvalid says the system does not provide us with extra time - in - to return; + - } the * $ Panax Notoginseng[Self performselector: @selector (Exitapp) Withobject:nil Afterdelay:180.0];//back into the background 3 minutes delay, log out - the + A } the +- (void) Applicationwillenterforeground: (UIApplication *) Application { - $ $ -[[UIApplication sharedapplication] endbackgroundtask:taskid];//cut back to the foreground, end the background task - the[NSObject cancelpreviousperformrequestswithtarget:selfselector: @selector (Exitapp)Object: nil];//Cancel the method that will exit before - Wuyi the - } Wu -
turn from; http://blog.sina.com.cn/s/blog_7f422a89010190jk.html
iOS implementation in the background, to achieve background tasks (turn from)