I have an macOS app that have timer and increase number every second. Every 60 second I show a notification with some message.
I found that my macOS Swift app runs with some delay, and after ~10 minutes started to sleep (no new a;lets appear anymore).
I have found some solutions, like this:
private func startTimer() {
timer = Timer.scheduledTimer(
timeInterval: 1.0,
target: self,
selector: #selector(timerTick),
userInfo: nil,
repeats: true
)
RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)
}
But this command don't helped me to fix the lag with background run of timer: RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)
Need some experienced Swift guy who can help me to solve this interesting challenge. I need to count seconds in background app correctly, because my app shows alert messages every few minutes, and if it can't show me these alerts correctly - my app will work not as I expected.
Thank you!