Code Note: obtains the background time required by the system to complete the task.

Source: Internet
Author: User

Code Note: obtains the background time required by the system to complete the task.

I. Code.

AppDelegate. h

# Import <UIKit/UIKit. h> @ interface AppDelegate: UIResponder <UIApplicationDelegate> @ property (strong, nonatomic) UIWindow * window; // Add variable @ property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundUpdateTask; @ end

 

AppDelegate. m

# Import "AppDelegate. h "# import" RootViewController. h "@ implementation AppDelegate-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; // Override point for customization after application launch. rootViewController * rootVC = [[RootViewController alloc] init]; UINavigat IonController * nav = [[UINavigationController alloc] initWithRootViewController: rootVC]; self. window. rootViewController = nav; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES;}-(void) applicationWillResignActive :( UIApplication *) application {// Sent when the application is about to move from active to inactive state. this can occur for certain types of te Mporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. games shocould use this method to pause the game .} -(void) applicationDidEnterBackground :( UIApplication *) application {[self beingBackground UpdateTask]; // Add the code you need to run for a long time. // Finally, complete the code again. [Self endBackgroundUpdateTask];}-(void) beingBackgroundUpdateTask {self. backgroundUpdateTask = [[UIApplication sharedApplication] balance: ^ {// you have to pay back it. [Self defined];}-(void) defined {[[UIApplication sharedApplication] endBackgroundTask: self. backgroundUpdateTask]; self. backgroundUpdateTask = UIBackgroundTaskInvalid ;}

 

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.