Search code examples
iossprite-kitbackground-task

IOS SpriteKit Increment life count when game enters background


I have created an SpriteKit game (My very first game :) ), and i want when the user loses all his lives in the game, after a period of time the life count to be returned to the original and notify the user that his lives have been restored (this code is executed even if the app is in background mode), just like Candy Crush does it. The only way i see it done is by using background tasks, but according to the following link i should specify what my background task will perform, and i don't know what exactly to select for my situation here:

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

So this is my problem, and i also want to ask if this is the right way to do what i want or is there another solution

Thanks in advance


Solution

  • You can schedule a UILocalNotification to trigger at a specific date/time to let the user know the status of the game while the app is in the background (or not running at all). You can then restore the life count when the game enters the foreground if the appropriate amount of time has elapsed.