在我的应用我有很长appWillEnterForeground:appDidEnterBackground之前被称为:完成
- (void)appDidEnterBackground:(NSNotification*)notif
方法,
它需要1-2秒来执行。这导致了以下问题:如果我关闭应用程序,然后再次打开速度非常快,比
- (void)appWillEnterForeground:(NSNotification*)notif
-appDidEnterBackground
完成之前被调用,从而导致崩溃 - 数据并不一致,或者是这样的。我不想调查我的数据中究竟出了什么问题,我想阻止这种情况的发生 - 我想等到appDidEnterBackground完成。
我的代码:
- (void)appDidEnterBackground:(NSNotification*)notif
{
[self processAppDidEnterBackgroundRoutines];
NSLog(@"%s - end", __FUNCTION__);
}
- (void)processAppDidEnterBackgroundRoutines
{
// 1-2 seconds prosessing
}
- (void)appWillEnterForeground:(NSNotification*)notif
{
NSLog(@"%s - begin", __FUNCTION__);
}
席力图召
[self performSelectorOnMainThread:@selector(processAppDidEnterBackgroundRoutines) withObject:nil waitUntilDone:YES];
,但它并不能帮助出于某种原因 - appWillEnterForeground:
processAppDidEnterBackgroundRoutines
完成之前仍然被调用。
有没有人有别人的想法如何同步此调用?
哦,没错,使用performSelectorOnMainThread:没有意义。但只需调用-processAppDidEnterBackgroundRoutines - 这是我的问题发生的原始情况。 performSelectorOnMainThread:只是一个尝试解决它。编辑我的问题。 – Anastasia