How to know which viewcontroller is presented at the beginning of the application


The situation is :

  • App is on background
  • The user click on icon app
  • App open and show the view controller where we were before apps entered background last time.

I'd like to know which view controller is about to be presented. I'm looking for something like :

- (void)applicationDidBecomeActive:(UIApplication *)application {
    if ([self.window.viewControllerOnScreen isKindOfClass:[HomeViewController class]]) {
        //do sthg

Because in case, it's the home view controller (embed in a navigation controller and i use storyboards) i would perform some reload method.

As per this link Each object receive a UIApplicationDidEnterBackgroundNotification notification when the app goes in background. Similarly UIApplicationWillEnterForegroundNotification gets fired when app comes in foreground.

so you can use it to keep track of which view controller is opened when app enters foreground

[[NSNotificationCenter defaultCenter] addObserver:self