问题描述
我试图在代码中到处搜索:解释文档在进入后台时它会做什么,或者它是否有时会暂停,但无济于事 - 有人可以指导我在去时建议做什么到启用精灵套件的游戏中的背景?
我应该只调用 scene.paused = YES
,还是我如何确认后台没有绘图,这样我才能避免被 iOS 终止,而这不允许我这样做?
谢谢!
如前所述 这里 by LearnCocos2D
:
问题是当应用进入后台时 AVAudioSession 无法激活.
修复非常简单,也适用于 ObjectAL =>;在应用处于后台时将 AVAudioSession 设置为非活动状态,并在应用进入前台时重新激活音频会话.
经过此修复的简化 AppDelegate 如下所示:
#import <AVFoundation/AVFoundation.h>...- (void)applicationWillResignActive:(UIApplication *)application{//防止音频崩溃[[AVAudioSession sharedInstance] setActive:NO error:nil];}- (void)applicationDidEnterBackground:(UIApplication *)application{//防止音频崩溃[[AVAudioSession sharedInstance] setActive:NO error:nil];}- (void)applicationWillEnterForeground:(UIApplication *)application{//恢复音频[[AVAudioSession sharedInstance] setActive:YES error:nil];}
PS:此修复将包含在 Kobold Kit 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
:
#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];
}
这篇关于SpriteKit-多任务的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!