I have the following in my touchesBegan function in my GameScene so that the timer only starts when the user touches a certain sprite:
let start = SKAction.runBlock({
NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "printDuration:", userInfo: NSDate(), repeats: true)
})
tapToStartNode.runAction(start)
and the following function:
func printDuration(timer: NSTimer) {
if self.view?.paused == false {
guard let userInfo = timer.userInfo else {
return
}
guard let startDate = userInfo as? NSDate else {
return
}
let duration = NSDate().timeIntervalSinceDate(startDate)
currentTime = NSDate().timeIntervalSinceDate(startDate)
currentTimeValueLabel.text = "\(NSString(format:"%3.2f", duration))"
}
}
However, when applicationDidEnterBackground or applicationWillResignActive the timer is not paused and continues to run when the app is in the backgorund. How do I make it stop?