Live Activity Widget -

Hi, I'm developing a Live Activity Widget that shows a count down timer. In the current solution I have a stop watch that is responsible for handling the start, stop, resume, reset function. When the stop watch starts I have timer that calls on an updateTime function every 0.2 seconds. This works well. The problems comes when I try to use my stop watch in the Live Activity Widget. I have a timer that updates the live activity attributes with content every 0.5 second.

// Start the activity 
let activity = try? Activity.request(...

DispatchQueue.main.async {
            self.logger.log("Start internal timer")
            self.timer = Timer.scheduledTimer(withTimeInterval:0.5, repeats: true) { _ in
                self.logger.log("Update activity widget.")
                self.updateActivity()
            }
        }

Is this a correct approach? If not what should I use to implement a stop watch with a count down timer and a corresponding progress bar/view?

Answered by Engineer in 794493022

The system will likely drop a lot if your update requests (performance, battery reasons). It is better to use a SwiftUI text with formatting as a timer and update at a more reasonable frequency. If you enable frequent updates, you should be fine every 15 seconds.

Rico
WWDR - Software Engineer

The system will likely drop a lot if your update requests (performance, battery reasons). It is better to use a SwiftUI text with formatting as a timer and update at a more reasonable frequency. If you enable frequent updates, you should be fine every 15 seconds.

Rico
WWDR - Software Engineer

Live Activity Widget -
 
 
Q