I'm writing an app in Swift where a timer counts down, much like a countdown clock. To do this I am using this code in my main logics class:
func start() {
self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in
self.run()
}
}
Now every time I close the app, the timer stops and I get this error:
BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended.
Is there any way to continue the timer running in the background? Or do you have any other, possibly more elegant, way to solve my problem? I have searched all over stackoverflow for this for hours now, but I can't seem to find an answer.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…