出于安全原因,我需要在进入后台之前而不是在进入前台之前清除应用程序的状态。applicationWillResignActive 中的代码执行,但视图的关闭没有显示,也没有生效,因为前一个视图仍然可见并且视图控制器没有从堆栈中删除。另一方面,applicationWillEnterForeground 中的代码执行并生效,因为dismissModalViewControllerAnimated 实际上正在转换视图并从堆栈中删除视图控制器。
我收到这个警告:
Warning: Attempt to dismiss from view controller <UINavigationController: 0x1e074c90> while a presentation or dismiss is in progress!
如何强制dismissModalViewControllerAnimated 生效并显示视图的转换并从堆栈中删除视图控制器?
- (void)applicationWillResignActive:(UIApplication *)application
{
[self initializeState];
}
- (void)initializeState
{
[self.appDelegateDelegate resetApp:self];
}
...
#pragma mark - AppDelegateDelegate
- (void)resetApp:(AppDelegate *)appDelegate
{
[SVProgressHUD dismiss];
[[EmployeeAPIClient sharedInstance] logout];
[self dismissModalViewControllerAnimated:NO];
}
但如果包含在 applicationWillEnterForeground: 中可以正常工作
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self initializeState];
}