1

I've tried this iOS Sprite Kit tutorial and have created a similar app. However, I notice that when I press the home button to go to iOS home screen, I get a bad access exception in xCode. When I go back into the app, it starts from the beginning.

How can I properly close/minimize a Sprite Kit app to avoid that exception?

I tried this within the view controller presenting the scene, but it does not get called:

-(void)viewWillDisappear:(BOOL)animated
{
    SKView * skView = (SKView *)self.view;
    skView.paused = YES;
    [super viewWillDisappear:animated];
}
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • Some more detail on what the exception is would help. – Dave Kasper Nov 11 '13 at 02:39
  • possible duplicate of [Home button press causes EXC\_BAD\_ACCESS code=1 in SpriteKit SKView](http://stackoverflow.com/questions/19058096/home-button-press-causes-exc-bad-access-code-1-in-spritekit-skview) – prototypical Nov 11 '13 at 05:12
  • 2
    possible duplicate of this one perhaps? Sprite Kit & playing sound leads to app termination: http://stackoverflow.com/questions/18976813/sprite-kit-playing-sound-leads-to-app-termination – CodeSmile Nov 11 '13 at 18:44
  • I think it is likely the issue as that tutorial has audio implementation. Thanks for that link, I was not aware. I think that question linked could probably be worded a bit better so that the going to background aspect is mentioned in the actual question title. – prototypical Nov 11 '13 at 19:53
  • The issue that I'm describing is a duplicate of the link above EXC_BAD_ACCESS code 0x1 . I checked and even the apple's "Adventure" demo project seems to restart after single tapping home. – Alex Stone Nov 14 '13 at 00:00

2 Answers2

0

I found out that there's Kobold Kit sprite engine built on top of Sprite Kit, after porting my project to that, i can minimize the app and restore it with the same stuff on the screen!

Alex Stone
  • 46,408
  • 55
  • 231
  • 407
-1

I believe that the proper way to handle minimizing an app is in the AppDelegate via these methods :

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
prototypical
  • 6,731
  • 3
  • 24
  • 34