Skip to content

Commit f792d74

Browse files
bjorkertmarionbarker
authored andcommitted
Auto-restart Live Activity when iOS sends .ended (#659)
When iOS reaches the Live Activity lifetime cap before renewal fires it delivers .ended, not .dismissed. The state observer only ran restart logic on .dismissed, so handleForeground saw renewalFailed=false and renewBy still in the future and returned "no action needed", leaving the LA dark until manual force-restart. Mark laRenewalFailed=true on the .ended path (gated on wasCurrent and !endingForRestart) so the next foreground entry triggers performForegroundRestart, which sweeps the corpse activity and pushes a fresh one.
1 parent 3eee687 commit f792d74

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

LoopFollow/LiveActivity/LiveActivityManager.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,20 @@ final class LiveActivityManager {
13941394
// • the user disables LA or calls forceRestart
13951395
LogManager.shared.log(category: .general, message: "[LA] activity cleared id=\(activity.id) state=\(state)", isDebug: true)
13961396
}
1397+
if state == .ended, wasCurrentActivity, !endingForRestart {
1398+
// iOS terminated the activity itself — typically the ~8h lifetime
1399+
// cap reached before renewal fired. The .dismissed path below
1400+
// already handles iOS-initiated dismissals via renewalFailed /
1401+
// pastDeadline, but .ended bypasses that branch entirely. Without
1402+
// a signal here, handleForeground() sees `renewalFailed=false` and
1403+
// `renewBy` still in the future, returns "no action needed", and
1404+
// startIfNeeded keeps re-binding the corpse — the LA stays dark
1405+
// until the user manually force-restarts. Mark renewalFailed so
1406+
// the next foreground entry runs performForegroundRestart, which
1407+
// sweeps any leftover ended activity and pushes a fresh one.
1408+
Storage.shared.laRenewalFailed.value = true
1409+
LogManager.shared.log(category: .general, message: "[LA] ended by iOS (not our restart) — marked renewalFailed=true, auto-restart on next foreground")
1410+
}
13971411
if state == .dismissed {
13981412
// Three possible sources of .dismissed — only the third blocks restart:
13991413
//

0 commit comments

Comments
 (0)