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