r/iOSProgramming • • 17d ago

Discussion Live Activity on a locked iPhone: staleDate updated 1–2 min late, an HKWorkoutSession made it on time (iOS 26)

I needed a Live Activity to change state at an exact time (end of a rest timer) while the phone is locked, without a push server.

staleDate + a stale view works, but once the app is suspended it renders 1–2 min late.

What worked: start an HKWorkoutSession on the iPhone (available since iOS 26). While it runs the app keeps running when locked, so the app's own timer calls activity.update() right on time. I only needed the HealthKit entitlement and the Health usage strings, no background mode (workout-processing is documented for watchOS only).

Caveats: it only makes sense if your app really runs a workout, the person has to allow Health, and I keep staleDate as the fallback when they don't.

Apple's docs don't say the session keeps an iPhone app alive, so this is only what I see on my iPhone 17. Anyone seen it behave differently on other devices or in long sessions? ;)

4 Upvotes

10 comments sorted by

1

u/Esmita-Suhre 17d ago

did you test this unplugged from the debugger? sometimes the system is way more lenient with background suspension when a cable is attached or a debug session was recently active, even after locking.

1

u/PierreMouchan 16d ago

Yes, unplugged, release build, phone locked in my pocket during a real session. Same result. But one device only, so I'd love more data points.

0

u/onefish857 17d ago

i'd be careful hanging a feature on that. if it isn't documented, a later point release can stop keeping the app alive and you only hear about it from users.

1

u/PierreMouchan 17d ago

Yeah I’ll double check

1

u/[deleted] 17d ago

[removed] — view removed comment

1

u/PierreMouchan 16d ago

That's what I have: the countdown is Text(timerInterval:countsDown:) and a local notification with sound fires at the rest end, so people who decline Health still get the alert. The session only matters for the Live Activity itself switching to its "rest done" state on time.

1

u/[deleted] 16d ago

[removed] — view removed comment

1

u/PierreMouchan 16d ago edited 15d ago

No server on my side, everything stays on the phone, so APNs is out. Making 0:00 already read as done is a nice fallback, I'll try that.