app额外后台运行操作

时间:2023-03-08 15:13:48
app额外后台运行操作

//在视图中运行操作中进行周期操作

- (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;

}