Search code examples
swiftswiftuiwidgetkitactivitykit

SwiftUI Text(_, style: .timer) bug in Live Activity


I added the Text(Date().addingTimeInterval(2400), style: .timer) in my Live Activity, but when its countdown to zero and the notification hasn't been delivered yet it starts to count up.

Is it can be fixed?

I tried to use the normal Timer but in the Live Activity it doesn't work


Solution

  • Use this initializer instead: https://developer.apple.com/documentation/swiftui/text/init(timerinterval:pausetime:countsdown:showshours:)

    So in your case:

    let range = Date()...Date().addingTimeInterval(2400)
    
    Text(
       timerInterval: range,
       pauseTime: range.lowerBound
    )