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

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -