1

I have a live activity that has a countdown timer. The timer can be minutes long. If my app is suspended the countdown timer reaches zero and then starts to count up. I have set the stale date of the ActivityContent to be the same date as the countdown timer. I have code in the widget that displays if the state is stale. This code is updated about 1:45 after the stale date has occurred.

How can I make sure the UI updates right when the stale date occurs when the app is suspended?

@available(iOS 16.2, *)
struct IsStaleWidget: Widget {
    var body: some WidgetConfiguration {
        ActivityConfiguration(for: MyActivityAttributes.self) { context in
            Text("\(context.isStale ? "Is" : "Not") stale")
        } dynamicIsland: { context in
            DynamicIsland {
                DynamicIslandExpandedRegion(.center) {
                    Text("\(context.isStale ? "Is" : "Not") stale")
                }
            } compactLeading: {
                Text("\(context.isStale ? "Is" : "Not")")
            } compactTrailing: {
                Text("Stale")
            } minimal: {
                Text("\(context.isStale ? "S" : "!S")")
            }
        }
    }
}

datinc
  • 3,404
  • 3
  • 24
  • 33
  • 1
    I have the same problem and cannot answer your question but I assume you're using `Text(date, style: .timer)` to display time left, right? If so I'd recommend to switch to `Text(timeInterval: startDate...endDate)` – this version of `Text` doesn't count up after reaching 0:00 – ramzesenok Aug 09 '23 at 21:28
  • When testing staleDate in my app it seems like a minimum staleDate is two minutes from now. If I set staleDate to something less than two minutes, the state is changed after two minutes. If I set staleDate in 2minutes and 10 seconds, the state is changed after 2 minutes and 10 seconds. So maybe there is a minimum time of 2 minutes. I cannot find anything in the documentation, so not sure what's going on (iOS 16.4) – KimHafr Aug 29 '23 at 18:05

0 Answers0