iosobjective-ciphonexcodehome-button

How to make iPhone application go to pause menu when home button is clicked?


I am making an iPhone application that is fairly simple. All I need to do is set the bool "paused" to true to pause the game. How can I make my application do that when the home button is hit?

Thanks guys, that was exactly what I wanted. Since it is in the appDelegate, though, I can't access the boolean "paused" to change it. How can I make it global so that I can access it from the appDelegate?


Solution

  • The Appdelegate.m of your app provides functions you can use to track if the Application will be entering the background;

    User pressed the button;

    - (void)applicationWillResignActive:(UIApplication *)application
    

    Application is in the background;

    - (void)applicationDidEnterBackground:(UIApplication *)application
    

    Within any of these functions you could set the BOOL to True/YES. -> See the comments provided by Apple within the functions for their exact usage.

    When the application becomes active again, the appdelegate will (again) fire a function;

    - (void)applicationDidBecomeActive:(UIApplication *)application