SpriteKit is supposed to clean up and pause all timers when you press the home button.
However, we have found that if you single tap the home button while displaying an active SKView, the app crashes. This occurs even if that view is already paused by the user.
Strangely, if you double tap the home button and move to the multitasking view, everything works fine.
Follow Up Note: The simulator works perfectly in both situations, no crash
Is anyone else seeing this issue with SpriteKit?
Have you found the cause / solution?
I was having the same problem and I solved it manually pausing the root SKView in the ViewController before the app moving to the background:
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view (already setup as SKView via storyboard)
SKView * skView = (SKView *)self.view;
// Create and configure the scene.
SKScene *scene = [Menu sceneWithSize:CGSizeMake(skView.bounds.size.height, skView.bounds.size.width)];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(appWillEnterBackground)
name:UIApplicationWillResignActiveNotification
object:NULL];
}
- (void)appWillEnterBackground
{
SKView *skView = (SKView *)self.view;
skView.paused = YES;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(appWillEnterForeground)
name:UIApplicationWillEnterForegroundNotification
object:NULL];
}
- (void)appWillEnterForeground
{
SKView * skView = (SKView *)self.view;
skView.paused = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(appWillEnterBackground)
name:UIApplicationWillResignActiveNotification
object:NULL];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With