views:

198

answers:

2

I want to implement this function on my apps but i cant seem to figure out how to use this line of codes.

- (void)applicationWillResignActive:(UIApplication *)application {
 //our app is going to loose focus since there is an incoming call
 [self pauseGame];
}

- (void)applicationDidBecomeActive:(UIApplication *)application{
 //the user declined the call and is returning to our app
 [self resumeGame];
}

I've read that this must be placed in appdelegates but i cant seem to figure out how could i call my pause action when the game is currently in the viewcontroller.

Thank you.

+5  A: 

Instead of sending the messages to self (which is the app delegate), you would send them to your view controller.

For example, if your app delegate had a property for your main game view controller named "gameViewController" (where the methods to pause and resume were implemented):

- (void)applicationWillResignActive:(UIApplication *)application {
    // our app is going to loose focus since there is an incoming call
    [self.gameViewController pauseGame];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // the user declined the call and is returning to our app
    [self.gameViewController resumeGame];
}
gerry3
ok got it. Im gonna try it later when i got back home. Thanks gerry3.
Drahc
ok I tried what you said but im getting lots of error now. The thing is that my main gamelogic is not in mymainViewController but rather on a seperate view on its own xib file. I'm getting "request for member in something not a structure or union". Thanks.
Drahc
I used the name "gameViewController" to mean whatever view controller had your game logic such that it made sense to put your methods for pause and resume in it. Usually that error means you did not define a property or import the header with the property.
gerry3