This is my escenario:
I have a view controller where the user can go to another application (Settings) when push a button in this way:
-(void) goToSettings{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
So, this code open the app's screen settings and it shows in the upper left corner a legend like this:
Back to myApplication
I wish to detect when the view controller where user push the button is active again. I know you can detect when app is active again with this method in the delegate file
- (void)applicationWillEnterForeground:(UIApplication *)application
But I need detect in specific the view controller. I have tried with -(void)viewWillAppear:(BOOL)animated
but It not works. Anyone have any idea about this?
The solution is simple: create a Boolean property called goingForwards in your view controller, and set it to true before pushing any view controller onto the navigation stack, then set it back to false when the view controller is shown again.
To dismiss a modally presented view controller, call the view controller's dismiss(animated:completion:) method.
There are two ways to be notified when your app moves to the background: implement the applicationWillResignActive() method in your app delegate, or register for the UIApplication. willResignActiveNotification notification anywhere in your app.
Setup your view controller to listen for the UIApplicationDidBecomeActiveNotification
notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(becomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
Then add the becomeActive:
method:
- (void)becomeActive:(NSNotification *)notification {
// App is active again - do something useful
}
And be sure to remove the observer at the appropriate point.
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
Of course your app may become active again for lots of reasons, not just returning from the Settings app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With