Pause Script set script when home button is pressed

I was wondering how I can pause the sprite set scene when the home button is pressed.

I found some answers here and tried it with a notification center like this.

When my scene loads:

 [[NSNotificationCenter defaultCenter]
          addObserver:self
          selector:@selector(applicationDidEnterBackground)
          name:UIApplicationDidEnterBackgroundNotification
          object:nil];

      

And then later on, a method that gets called if it enters the background:

 - (void) applicationDidEnterBackground{
     NSLog(@"Enter to background");
     self.scene.view.paused  =YES;
 }

      

The problem is I am getting the NSLog message so the applicationDidEnterBackground method is being called correctly. But the problem is, when I go back to the application, my application is not paused.

So my pause statement (self.scene.view.paused = YES;) is not getting called?

If I put the exact expression somewhere else in the code, or if I make a pause button with that expression, then the pause works fine.

What is the problem? Why won't this work with Action Center?

+3


source to share


2 answers


Sprite Kit for iOS 8 automatically resumes the game after exiting the background. This happens after calling applicationDidBecomeActive. Plus, Sprite Kit for iOS 8 will automatically pause the game when it is moved to the background.

Update: The following are the skView.paused states when entering / exiting background for Xcode 5 and 6.

Xcode 6

Deployment targets 7.0, 7.1 **, 8.0, and 8.1

applicationWillResignActive = NO
applicationDidEnterBackground = YES
applicationWillEnterForeground = YES
applicationDidBecomeActive = YES

      



** When I started the device with iOS 7.1, the states were NO

Xcode 5

Deployment targets 7.0 and 7.1

applicationWillResignActive = NO
applicationDidEnterBackground = NO
applicationWillEnterForeground = NO
applicationDidBecomeActive = NO

      

+4


source


By the time your app has gone into the background, it might be too late.



Instead, we have to register for the notification UIApplicationWillResignActiveNotification

and only process our code before exiting when we receive that notification.

+1


source







All Articles