Mythrid12 Mythrid12 - 1 month ago 17x
iOS Question

Call function in applicationdidbecomeactive - Swift 2.0

So, I've got a func in my GameScene.swift file that I'd like to call every time my game becomes active. Currently I'm running this function in didMoveToView in my GameScene.swift file but it only runs when the app launches after being completely closed and I'd like to do it every time the game becomes active. (user hits home button and then re-opens app)

I assume running the func in applicationdidbecomeactive in the AppDelegate.swift file would work but I'm not sure how to do this or if it's actually possible. Any help would be appreciated.


You can add an observer in your GameScene.swift for UIApplicationDidBecomeActiveNotification and call your function. e.g.

selector: #selector(GameScene.yourfunction,
name:UIApplicationDidBecomeActiveNotification, object: nil)