Spritekit crashes when entering background

自闭症网瘾萝莉.ら 提交于 2019-12-01 03:43:21

Allright, I found the issue.

Behind the scenes, Spritekit uses AVAudioSession (which makes sense) for [SKAction playSoundFileNamed:]

AVAudioSession cannot be active while the application is in the background, so we have to stop it when going in to background, and reactivate it when entering foreground.

Use this piece of code in both applicationWillResignActive and applicationDidEnterBackground to disable the AVAudioSession:

[[AVAudioSession sharedInstance] setActive:NO error:nil];

To enable it again, use this in applicationWillEnterForeground:

[[AVAudioSession sharedInstance] setActive:YES error:nil];
Krzysztof Przygoda

It's not enough, while setActive:NO often ends with error (no deactivation in effect) which still leads to the crash.

Full solution I've described here: Sprite Kit & playing sound leads to app termination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!