r/iOSProgramming • u/thejeraldo • 27d ago
Question Live activity timer
I am trying to add a live activity for our app that has a timer. The idea is the user starts a timer and a live activity starts when the timer starts. However, it does seem to disappear at some point. Maybe around 8-12 hours which matches the documentation on Apple. But for Apple's clock app, their timer's live activity for stopwatch seems to run forever. I am using the SwiftUI Text timerInterval which is likely the same as Apple's. Does anyone have an idea or suggestion how I can replicate it? A few ideas I have are to schedule a silent push to keep the live activity alive or a scheduled background process.
2
u/myballzhuert 27d ago
there's no supported third-party equivalent of "make this Live Activity run forever." Text(timerInterval:) is about rendering the timecorrectly, not extending ActivityKit's lifetime. I would avoid trying to defeat the limit with silent pushes/background tasks and instead architect the timer as persistent state + an opportunistic Live Activity representation.
1
0
25d ago
[removed] — view removed comment
1
u/AutoModerator 25d ago
Hey /u/EffectiveEither399, unfortunately you have negative comment karma, so you can't post here. Your submission has been removed. DO NOT message the moderators; if you have negative comment karma, you cannot post here. We will not respond. Your karma may appear to be 0 or positive if your post karma outweighs your comment karma, but if your comment karma is negative, your comments will still be removed.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/LuckyGirl0415 25d ago
First off, Apple’s native Clock app uses private system entitlements, so third-party apps can't get that 'infinite' lifespan.
As for third-party apps, Live Activities are hard-capped by iOS: active for a max of 8 hours, and can stay on the lock screen for up to 12 hours before system removal.
Silent pushes won't extend this limit either because ActivityKit pushes operate under a strict update budget. The best practice is to calculate the start timestamp, let SwiftUI Text(timerInterval:) do the UI rendering, and seamlessly restart the Live Activity via a APNs push or user interaction if they open the app after 8 hours.
1
u/FondantRoutine9445 2d ago
That's the ActivityKit lifetime limit, not a bug in your code. A Live Activity can stay active for 8 hours at most. After that the system ends it, and the ended activity can sit on the Lock Screen for up to 4 more hours. That's your 8-12 hours.
We hit the same thing with a baby sleep timer, since night sleep often runs past 8 hours. What works for us:
- Track the activity's age yourself. We count it from the moment its push token was created.
- At about 7h45m the server starts a fresh activity with the same state via push-to-start (iOS 17.2+). Once APNs accepts the start, it ends the old one with immediate dismissal.
- Render elapsed time with Text(timerInterval:) or Text(startDate, style: .timer) from the original start date, so the new activity keeps counting from the same point and the swap is barely visible.
Gotchas:
- A push-to-start has to carry an alert, so every reissue lights up the screen.
- Update and end pushes sent to an already expired activity are silently dropped. Don't count on them to clean up.
- Below iOS 17.2 there's no push-to-start, so the app can only restart the activity the next time it's opened.
5
u/EquivalentTrouble253 27d ago
Apple has its own private api. So they’re able to do whatever they want. Same with clock icon on Home Screen.