iOS implementation in the background, to achieve background tasks (turn from)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.