//在视图中运行操作中进行周期操作
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self beingBackgroundUpdateTask];
[self endBackgroundUpdateTask];
}
- (void)beginBackgroundUpdateTask{
self.backgroundUpdateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
///在多于5s中做的清理工作
[self endBackgroundUpdateTask];
}];
}
- (void)endBackgroundUpdateTask{
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundUpdateTask];
self.backgroundUpdateTask = UIBackgroundTaskInvalid;
}
原文地址:https://www.cnblogs.com/tryFighting/p/8178533.html
时间: 2024-10-04 11:46:01