雪碧套件 &播放声音导致应用程序终止 [英] Sprite Kit & playing sound leads to app termination

查看:33
本文介绍了雪碧套件 &播放声音导致应用程序终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是我遇到的一个问题-我有一个 SKScene,我在其中使用 SKAction 类方法播放声音效果

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];

现在,当我尝试进入后台时,无论声音是否结束,显然 iOS 由于 gpus_ReturnNotPermittedKillClient 正在终止我的应用程序.

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.

现在只有当我评论这一行而不运行操作时,iOS 才会在后台运行它(当然,暂停,但没有终止).

Now only when I comment this line and not running the action iOS runs it great in background (of course, paused, but without termination).

我做错了什么?

EDIT:如果该行未运行,iOS 将不会终止应用程序 - 例如,如果它位于未运行的 if 语句(soundOn == YES) 或类似的东西,当 bool 为 false

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

推荐答案

问题是 AVAudioSession 在应用进入后台时无法激活.这不是很明显,因为 Sprite Kit 没有提到它在内部使用 AVAudioSession.

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.

修复非常简单,也适用于 ObjectAL => 在应用程序处于后台时将 AVAudioSession 设置为非活动状态,并在应用程序进入前台时重新激活音频会话.

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.

经过此修复的简化 AppDelegate 如下所示:

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:此修复将包含在 Kobold Kit v7.0.3 中.

PS: this fix will be included in Kobold Kit v7.0.3.

这篇关于雪碧套件 &amp;播放声音导致应用程序终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆