r/iOSProgramming • u/PierreMouchan • 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? ;)
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.
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/[deleted] 17d ago
[removed] — view removed comment