Question

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?

Was it helpful?

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

OTHER TIPS

In your AppDelegate there are two method which is called when the button is called

You can pause the game here:

 - (void)applicationDidEnterBackground:(UIApplication *)application
    {
          //Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    }

or here:

    - (void)applicationWillResignActive:(UIApplication *)application{
       //Sent when the application is about to move from active to inactive state.
    }

In your app delegate, implement applicationWillResignActive:. Set paused = YES; there. Reset it in applicationDidBecomeActive:.

- (void)applicationWillResignActive:(UIApplication *)application

implement your pause method and it will be called when your app is going to become inactive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top