ios - Pause NSTimer when app goes to background -
i have following in touchesbegan function in gamescene timer starts when user touches sprite:
let start = skaction.runblock({ nstimer.scheduledtimerwithtimeinterval(0.1, target: self, selector: "printduration:", userinfo: nsdate(), repeats: true) }) taptostartnode.runaction(start)
and 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 timer not paused , continues run when app in backgorund. how make stop?
Comments
Post a Comment