I need to purge the state of the app before going background and not before coming foreground for security reasons. The code in applicationWillResignActive executes but the dismissal of the view is not shown nor does it take effect since the previous view remains on sight and the viewcontroller is not removed from the stack. On the other hand the code in applicationWillEnterForeground executes and takes effect as the dismissModalViewControllerAnimated is actually transitioning views and removing the view controller form the stack.
I get this warning:
Warning: Attempt to dismiss from view controller <UINavigationController: 0x1e074c90> while a presentation or dismiss is in progress!
How can I force the dismissModalViewControllerAnimated to take effect and show the transisions of views and remove the view controller from the stack?
- (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];
}
But if included in applicationWillEnterForeground: works correctly
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self initializeState];
}