Swift 2.3, SpriteKit
I know about AppDelegate Functions:
applicationWillResignActive
and applicationDidEnterBackground
I have the following code:
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
mainScene.view?.paused = true
}
func applicationDidEnterBackground(application: UIApplication) {
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
mainScene.view?.paused = true
}
With applicationDidEnterBackground
it works fine. I'm able to pause the scene by tapping Home Button and resume it after.
But with applicationWillResignActive
it doesn't work. When I run my game and receive Phone Call, the game doesn't pause. It keeps running in the background, so when I'm done with call and go back, I can see all my nodes in a completely mess.
I used print
statement to check if applicationWillResignActive
works when I receive a phone Call and it shows me that it is executing, but the app just doesn't pause.
Also I've noticed that when I tap Home Button the app call applicationWillResignActive
and then applicationDidEnterBackground
functions. When I receive a phone call only applicationWillResignActive
function is called.
So my question is - how can I deal with phone calls and pause my App with applicationWillResignActive
function. I don't understand why I can pause it when I tap Home Button and can't when I get a Phone Call.