0
votes

In my game, I have functions to pause and unpause an SKNode that contains the gameplay elements. Currently, the system automatically pauses when the home button is pressed, and unpauses when the app becomes active again.

I would like to do this on my own terms. For instance, when the app becomes active again, it should show the pause menu, and stay paused until the user manually unpauses.

Is there a way to override this system behavior?

2

2 Answers

0
votes

You can register to receive the UIApplicationDidEnterBackgroundNotification or UIApplicationWillEnterForegroundNotification notification, and trigger the pause menu in the notification selector.

0
votes

Somewhere in your code, you'd have to register a notification. There are plenty of notifications to choose from. Here is one for when the App comes back from the background:

override func viewDidLoad() {
    super.viewDidLoad()
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive:", name: UIApplicationDidBecomeActiveNotification, object: nil)
}

func didBecomeActive(test: NSNotification) {
    self.unpause()
}

Notice that the selector in the addObserver method is the name of the function that will be called when the application comes back from the background. Also the didBecomeActive method needs an argument of type NSNotification.