| // AppDelegate.h 文件 @PRoperty (assign, nonatomic) UIBackgroundTaskIdentifierbackgroundUpdateTask; // AppDelegate.m 文件 - (void)applicationDidEnterBackground:(UIApplication *)application { [self beingBackgroundUpdateTask]; // 在这里加上你需要长久运行的代码 [self endBackgroundUpdateTask]; } -(void)beingBackgroundUpdateTask { self.backgroundUpdateTask = [[UIApplicationsharedApplication] beginBackgroundTaskWithExpirationHandler:^{ [selfendBackgroundUpdateTask]; }]; } - (void)endBackgroundUpdateTask {[[UIApplication sharedApplication] endBackgroundTask:self.backgroundUpdateTask]; self.backgroundUpdateTask = UIBackgroundTaskInvalid;}
|