GCD-block-Background running, gcd-block-Background

Source: Internet
Author: User

GCD-block-Background running, gcd-block-Background

When an app exits by pressing the home key, it only takes up to 5 seconds to save or clear resources. However, if you call the beginBackgroundTaskWithExpirationHandler method, you can run it in the background at most 10 minutes. We can use this time to clean up the local cache and send statistics.

 

AppDelegate. h

 

# Import <UIKit/UIKit. h> @ interface AppDelegate: UIResponder <UIApplicationDelegate> @ property (strong, nonatomic) UIWindow * window; // long-running background @ property (assign, nonatomic) implements backgroundUpdateTask; @ end

 

 

 

AppDelegate. m

 

// When the app enters the background-(void) applicationDidEnterBackground :( UIApplication *) application {[self beingBackgroundUpdateTask]; // code that requires long-term running [self endBackgroundUpdateTask];} # pragma-mark-functions-(void) beingBackgroundUpdateTask {self. backgroundUpdateTask = [[UIApplication sharedApplication] usage: ^ {[self endBackgroundUpdateTask] ;}];}-(void) usage {[[UIApplication sharedApplication] endBackgroundTask: self. backgroundUpdateTask]; self. backgroundUpdateTask = UIBackgroundTaskInvalid ;}

 

 

 

References:

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

 

Related Article

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.