-1

I am using NSTimer for a timing app. The timer pushes an update to the timer which is sitting in the system bar at the top of the screen.

One of my users noticed something strange that when they are running another app in full screen- then the timer seems to lose 10% of the time. But if the other app is not in full screen- then its totally bang on right time.

Is there a flaw with my approach:

the following method is triggered by the timer function:

@objc func update() {
    currentTime += 1
    updateMenuTimer()
}
private func updateMenuTimer() {
    guard let timeString = currentTimeString else { return }
    appDel?.updateMenuTimer(newTime: timeString)
}
// In AppDelegate I manage the status bar view
func updateMenuTimer(newTime: String) {
    statusItem.button?.title = newTime
}
PPL
  • 6,357
  • 1
  • 11
  • 30
UKDataGeek
  • 6,338
  • 9
  • 46
  • 63

1 Answers1

0

NSTimer is not meant to be that accurate, this post describes this a bit and has some quoted documentation: Accuracy of NSTimer . I would recomend using the timer on short intervals to notify your UI to update based on a variable you save initially when the timer is started.

Alex
  • 3,861
  • 5
  • 28
  • 44