applicationDidEnterBackground, playSoundFileNamed Crash

165 views Asked by At

When I tap Home Button the app calls AppDelegate function applicationDidEnterBackground, and applicationWillEnterForeground after I get back to it.

I use the following code:

    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
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

        mainScene.view?.paused = false
    }

and it works fine. I'm able to pause the app and resume it when needed. But if I tap Home Button at the moment when there is a sound (like "gun Fire", or "Coin fall Down" etc.) currently playing in my app with SKAction.playSoundFileNamed and then try to resume the app, it crashes. The only way I can resume it normally it is if there aren't any active sounds when I tap Home Button.

Any workaround?

0

There are 0 answers