iOS 7.1 Sprite Kit AVAudioSession Crash when enter background

后端 未结 2 668
时光说笑
时光说笑 2021-02-11 06:22

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

2条回答
  •  长情又很酷
    2021-02-11 06:53

    I did it!

    I just paused the SKView in- (void)applicationWillResignActive:(UIApplication *)application and included the AVAudioSession set to inactive.

    AppDelegate.h

       #import 
    

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

提交回复
热议问题