I think you will try NSNotificationCenter as follows:
inside applicationDidEnterBackground and applicationWillEnterForeground put this
[[NSNotificationCenter defaultCenter] postNotificationName:@"popToRoot" object:nil];
and in your rootViewController's viewDidLoad (which always appears when the application starts) add this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popToRootViewControllerAnimated) name:@"popToRoot" object:nil];
Then create a method in rootViewController :
- (void)popToRootViewControllerAnimated { [self.navigationController popToRootViewControllerAnimated:YES]; }
Whenever the application is launched for the first time, NSNotificationCenter initializes the name popToRoot and prepares the popToRootViewControllerAnimated method for it.
And when the application goes to the background, NSNotificationCenter will pass the massage method @"popToRoot" to rootViewController popToRootViewControllerAnimated and viewcontroller will appear in rootview
source share