- (void)run
{
UIApplication *application = [UIApplication
sharedApplication];
__block
UIBackgroundTaskIdentifier background_task;
background_task = [application
beginBackgroundTaskWithExpirationHandler: ^ {
[self
hold];
[application
endBackgroundTask: background_task];
background_task =
UIBackgroundTaskInvalid;
}];
}
- (void)hold
{
_holding = YES;
while (_holding) {
[NSThread
sleepForTimeInterval:1];
CFRunLoopRunInMode(kCFRunLoopDefaultMode,
0, TRUE);
}
}
- (void)stop
{
_holding = NO;
DLog(@"end");
}
在applicationDidEnterBackground里面调用run方法