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
Asked
Active
Viewed 1,661 times
2
-
Any help from Apple Dev Forums? – AndrewShmig Mar 14 '14 at 15:39
-
Do you use runAction ^completion? – El Tomato Mar 14 '14 at 15:52
2 Answers
8
I did it!
I just paused the SKView in- (void)applicationWillResignActive:(UIApplication *)application
and included the AVAudioSession set to inactive.
AppDelegate.h
#import <SpriteKit/SpriteKit.h>
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];
}

ObjectiveCsam
- 204
- 1
- 8
0
adding to @ObjectivesCsam answer:
when rootViewControllers view is not SKView u can use
- (SKView *)getGameView {
NSArray *viewControllers = self.window.rootViewController.childViewControllers;
for (UIViewController *vc in viewControllers) {
if ([vc.view isKindOfClass:[SKView class]]) {
SKView *view = (SKView *)vc.view;
return view;
}
}
return nil;
}

Maq
- 369
- 3
- 13