Auto-restart Live Activity when iOS sends .ended#659
Open
bjorkert wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When iOS reaches the Live Activity lifetime cap (~8h) before our renewal fires, it terminates the activity with
.ended(not.dismissed). TheattachStateObserverrestart logic only ran on.dismissed, so after an iOS-initiated.ended:handleForegroundsawrenewalFailed=falseandrenewBystill in the future → "no action needed".startIfNeededrepeatedly re-bound the corpse activity (activities=1,current=nilafter eachbind → .ended → clear).Fix
In
attachStateObserver, whenstate == .endedfor the currently-tracked activity and we didn't initiate the end ourselves (!endingForRestart), setlaRenewalFailed = true. The next foreground entry then takes the existing renewal-failure path throughhandleForeground→performForegroundRestart, which ends any leftover activities and pushes a fresh one.Guards:
wasCurrentActivity— ignore late.endeddeliveries from stale observers for activities we no longer track.!endingForRestart— our own planned restarts already set the right flags downstream..dismissedbranch is unchanged, so user-swipe handling is unaffected.Repro
Real-world log from today shows the issue:
6848B03Cadopted,staleIn=26999s.[LA] activity cleared id=… state=ended.foreground: no action needed (not in renewal window),startIfNeededseesactivities=1, current=nil, no restart fires.