I have added an observer to my app that listens when the app goes into background mode. I did that through this command:
NotificationCenter.default.addObserver(self, selector: #selector(enterBackground), name: UIApplication.willResignActiveNotification, object: nil)
Now I want my selector to run a timer.scheduled in the background. My code Looks like:
@objc func enterBackground() {
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { (timer) in
print(self.secondsCount)
self.secondsCount -= 1
}
}
But the timer doesn’t print my print commands every second. Just once.
Does somebody know how to do that? Warm greetings!
AND NO! THIS ISN'T A DUPLICATE I READ A LOT OF ANSWERS AND QUESTIONS BUT I DID'T GET ANSWER FOR ME!