I made a game in spritekit with Swift and want to add lives even when the game is closed like candy crush does.
DO I have to use NStimeinterval or does this stop when game stops?
I made a game in spritekit with Swift and want to add lives even when the game is closed like candy crush does.
DO I have to use NStimeinterval or does this stop when game stops?
For what is possible and what is needed for background execution I recommend you read App Programming Guide: Background Execution.
But why is it neccessary to process this every 10 minutes even if the app is not running?
What about the following idea: Save the current system time in NSUserDefaults
when the app stops running (i.e. in UIApplication.applicationWillResignActive
or UIApplication.applicationDidEnterBackground
). When the app gets active again (or even starts from scratch if the user has completely terminated it) read that timestamp from NSUserDefaults
, calculate how many 10 min intervals have passed and add that to your live counter.
This way there is no need to take all the complex steps for background execution.
Just an idea.