Pause the game when someone calls / SMS, you

I want to implement this function in my applications, but I cannot figure out how to use this line of code.

- (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 read that this should be placed in appdelegates, but I can’t understand how I can name my pause action when the game is currently in the viewcontroller.

Thank.

+3
source share
2 answers

Instead of sending messages yourself (this is the application delegate), you send them to your view controller.

, "gameViewController" ( ):

- (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];
}
+6

, -. , ( ) (, UIViewControllers) UIApplicationDidEnterBackgroundNotification UIApplicationWillEnterForegroundNotification.

, Application , , , / .

+1

Source: https://habr.com/ru/post/1729512/


All Articles