iOS 7.1 Sprite Kit AVAudioSession输入后台时崩溃 [英] iOS 7.1 Sprite Kit AVAudioSession Crash when enter background
问题描述
所以2周前我向应用程序商店提交了一个sprite kit应用程序,一切都很好。在我提交应用程序之前我遇到了问题因为AvAudioSession会崩溃,但是我能够通过这个解决这个问题 Sprite Kit&播放声音会导致应用终止。这基本上将AVAudioSession设置为进入后台时处于非活动状态,然后在进入前台时再次激活。我最近更新了我的手机iOS 7.1,这个修复似乎不适用于新的7.1,我的应用程序在进入后台时再次崩溃。我已经从我的应用程序中取出所有音频,它似乎工作正常,所以它是我刚才解决方案不起作用的问题!我真的需要解决这个问题,因为我有一个更新准备提交..
干杯萨姆
So 2 weeks ago I submitted a sprite kit app to the app store and it all was fine. I was having problems before i submitted the app where it would crash because of AvAudioSession, however i was able to fix that problem through this Sprite Kit & playing sound leads to app termination. This basically sets AVAudioSession to inactive when going into background and then active again when coming into foreground. I recently update my phone it iOS 7.1 and this fix doesn't seem to work in the new 7.1 and my app is again crashing whenever it enters the background. I have taken all the audio out of my app and it seems to work fine so it is the same problem as i had before just now the solution doesn't work!I really need to fix this problem as i have an update ready to submit.. Cheers Sam
推荐答案
我做到了!
我只是在 - (void)applicationWillResignActive:(UIApplication *)应用程序
中暂停了SKView并包含了AVAudioSession集不活跃。
I just paused the SKView in- (void)applicationWillResignActive:(UIApplication *)application
and included the AVAudioSession set to inactive.
AppDelegate.h
AppDelegate.h
#import <SpriteKit/SpriteKit.h>
AppDelegate.m
AppDelegate.m
- (void)applicationWillResignActive:(UIApplication *)application
{
// prevent audio crash
[[AVAudioSession sharedInstance] setActive:NO error:nil];
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[AVAudioSession sharedInstance] setActive:NO error:nil];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = NO;
[[AVAudioSession sharedInstance] setActive:YES error:nil];
}
这篇关于iOS 7.1 Sprite Kit AVAudioSession输入后台时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!