i think you try NSNotificationCenter
like this:
inside applicationDidEnterBackground
and applicationWillEnterForeground
put this
[[NSNotificationCenter defaultCenter] postNotificationName:@"popToRoot" object:nil];
and in your rootViewController's
viewDidLoad
(that always appears on app launch) add this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popToRootViewControllerAnimated) name:@"popToRoot" object:nil];
Then create a method in your rootViewController
:
- (void)popToRootViewControllerAnimated
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
Whenever the application will start first time, NSNotificationCenter
will initialize for name popToRoot
and prepare a method popToRootViewControllerAnimated
for this.
And when application will go to background, NSNotificationCenter
will pass a massage @"popToRoot"
to rootViewController's popToRootViewControllerAnimated
method and viewcontroller
will pop to rootview
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…