"Reading notes" ios-gcd-block-backstage execution

Source: Internet
Author: User

When an app presses the home key to exit. There is only a maximum of 5 seconds to do some work to save or clean up resources.

However, the Beginbackgroundtaskwithexpirationhandler method is called and can be executed in the background up to 10 minutes. We can use this time to clean up the local cache, send statistics, and so on.

AppDelegate.h

#import <UIKit/UIKit.h> @interface appdelegate:uiresponder <UIApplicationDelegate> @property (Strong, nonatomic) UIWindow *window;//background Long execution @property (assign, nonatomic) Uibackgroundtaskidentifier backgroundupdatetask;@ End

Appdelegate.m

When the app enters the background-(void) Applicationdidenterbackground: (uiapplication *) application {    [self Beingbackgroundupdatetask];    Code that requires long execution    [self endbackgroundupdatetask];} #pragma-mark-functions-(void) beingbackgroundupdatetask{    self.backgroundupdatetask = [[UIApplication Sharedapplication] beginbackgroundtaskwithexpirationhandler:^{        [self endbackgroundupdatetask;    }];} -(void) endbackgroundupdatetask{    [[UIApplication sharedapplication] Endbackgroundtask: Self.backgroundupdatetask];    Self.backgroundupdatetask = Uibackgroundtaskinvalid;}

References:

http://www.devtang.com/blog/2012/02/22/use-gcd/


"Reading notes" ios-gcd-block-backstage execution

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.