Search code examples
iosdelegatesonresumehome-button

Which delegate function is called within a class on tapping the home-button


I have a pop-up which has to be hidden when the user moves away from the class. On tapping on the home button, the doesn't happen.

- (void)applicationDidBecomeActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

Other than the above functions is there any other delegate functions which would be called in the same class (not the app-delegate class).


Solution

  • Only the UIApplicationDelegate defines those methods. If you want any other class to handle those events, you need to have the class register for the corresponding notification.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgrounding) name:UIApplicationDidEnterBackgroundNotification object:nil];
    

    And don't forget to remove the observer.

    Then you need the method:

    - (void)backgrounding {
        // App entered background
    }