更新时间:2023-02-03 09:07:18
作为说按这里 LearnCocos2D
:
而应用程序进入后台问题是AVAudioSession不能活动。
解决方法是相当简单,而且也适用于ObjectAL =>设置AVAudioSession为无效,而应用程序是在后台,当应用程序进入前景激活音频会话。
此修复程序简化的AppDelegate看起来像这样:
块引用>#进口< AVFoundation / AVFoundation.h>... - (无效)applicationWillResignActive:(UIApplication的*)的应用
{
// prevent音频崩溃
[AVAudioSession sharedInstance] SETACTIVE:没有错误:无];
} - (无效)applicationDidEnterBackground:(UIApplication的*)的应用
{
// prevent音频崩溃
[AVAudioSession sharedInstance] SETACTIVE:没有错误:无];
} - (无效)applicationWillEnterForeground:(UIApplication的*)的应用
{
//恢复音频
[AVAudioSession sharedInstance] SETACTIVE:YES错误:无];
}
PS:此修复程序将包含在狗头包v7.0.3
块引用>I tried to search everywhere in the code:Explained documentry what it does when going to background, or if it is even paused sometime, but to no avail- can someone direct me in the way of what is recommended to do when going to background in sprite kit enabled game?
Should I just call
scene.paused = YES
, or how can I confirm that no drawing occurs in background so I can avoid termination by iOS which won't allow me that?Thanks!
As said here by
LearnCocos2D
:The problem is AVAudioSession can't be active while the app enters background.
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.