Its possible pause a Timer when Control Center appears in SpriteKit?

56 views Asked by At

I would Like to Know if it's possible pause a Timer when Control Center is Activated on iOS, on my project, my timer creates shapes and when the central control appears the game doesn't stop and accumulate a lot of nodes in the game.

2

There are 2 answers

1
Eduard On

There're 2 methods in UIApplicationDelegate for that:

Called when opened control center: applicationWillResignActive

When closed: applicationDidBecomeActive

Somehow opening/closing Notification Center makes it launch corresponding method twice (with opposite method in between).

But you need to make sure your timer is accessible from the scope of appdelegate.

0
Knight0fDragon On

You can't pause a Timer, the only thing you can do is track how much time has elapsed with .now - timer.fireDate or timer.timeInterval (all depends on how you are using the timer), cancel the timer, then restart it when your app is running again. It is a real pain in the @$$ and is strongly recommended to not be used. I would recommend using the built in SKActions to create all the timers you need, this way when you pause the scene, the timers pause with it. That of course goes beyond the scope of this question.