播放声音会导致应用程序终止

播放声音会导致应用程序终止

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

问题描述

只是我碰到入─问题
我有一个SKScene中,我使用播放声音FX 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).

我在做什么错了?

修改:iOS版不会终止应用程序,如果该行不计算─也就是说,如果是在一个 if语句的WASN 'T运行(soundOn == YES)或类似的东西,当布尔是

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 而应用程序进入背景不能活动。这不是显而易见的,因为雪碧套件并没有提及它使用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:此修复程序将包含在 v7.0.3

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

09-02 08:35