Just a problem I've run into- I have an SKScene in which I play a sound fx using SKAction class method
[SKAction playSoundFileNamed:@"sound.wav" waitForCompletion:NO];
Now when I try to go to background, no matter that the sound was over, apparently iOS is terminating my app due to gpus_ReturnNotPermittedKillClient
.
Now only when I comment this line and not running the action iOS runs it great in background (of course, paused, but without termination).
What am I doing wrong?
EDIT: iOS will not terminate the app if the line wasn't run- say, if it was in an if statement
that wasn't run (soundOn == YES)
or something like that, when the bool is false
SpriteKit is a general-purpose framework for drawing shapes, particles, text, images, and video in two dimensions. It leverages Metal to achieve high-performance rendering, while offering a simple programming interface to make it easy to create games and other graphics-intensive apps.
SpriteKit is easy to learn because it is a well-designed framework and it is even easier if you have experience with Swift. Even for a beginner, if you want to create your first game, 2D games is without a doubt the best way to transit in this new world.
SpriteKit is a game development engine released by Apple in 2013. As such, it's widely considered the best option for developing Apple-based games.
The problem is AVAudioSession
can't be active while the app enters background. This isn't immediately obvious because Sprite Kit makes no mention that it uses AVAudioSession internally.
The fix is quite simple, and also applies to ObjectAL => set the AVAudioSession
to inactive while the app is in background, and reactivate the audio session when the app enters foreground.
A simplified AppDelegate with this fix looks like so:
#import <AVFoundation/AVFoundation.h> ... - (void)applicationWillResignActive:(UIApplication *)application { // prevent audio crash [[AVAudioSession sharedInstance] setActive:NO error:nil]; } - (void)applicationDidEnterBackground:(UIApplication *)application { // prevent audio crash [[AVAudioSession sharedInstance] setActive:NO error:nil]; } - (void)applicationWillEnterForeground:(UIApplication *)application { // resume audio [[AVAudioSession sharedInstance] setActive:YES error:nil]; }
PS: this fix will be included in Kobold Kit v7.0.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With