雪碧套件 &播放声音导致应用程序终止

编程入门 行业动态 更新时间:2024-10-10 21:31:48
本文介绍了雪碧套件 &播放声音导致应用程序终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

只是我遇到的一个问题-我有一个 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;播放声音导致应用程序终止

本文发布于:2023-11-12 13:28:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:雪碧   套件   应用程序   声音   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!