Refresh on cold launch so notifications don't require pull-to-refresh#8
Open
useruserdev wants to merge 1 commit into
Open
Refresh on cold launch so notifications don't require pull-to-refresh#8useruserdev wants to merge 1 commit into
useruserdev wants to merge 1 commit into
Conversation
The launch refresh was wired only to onChange(of: scenePhase) for .active. scenePhase is already .active on cold launch, so onChange never fires for it and refreshAll() (which detects changes and posts notifications) never ran at startup. Updates only surfaced after a manual pull-to-refresh. Trigger the refresh from .task, which reliably runs once on first appearance. The onChange(.active) handler stays for background->foreground returns; refreshAll()'s isRefreshing guard makes any overlap a no-op.
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.
Problem
Notifications only appeared after a manual pull-to-refresh.
Cause
The launch refresh was wired only to
onChange(of: scenePhase)for.active. On a cold launch the scene is already.activewhen the closure registers, soonChangenever delivers that initial value —refreshAll()(which detects config changes and posts notifications) never ran at startup. It only ran on pull-to-refresh, on background→foreground returns, or via the rarely-scheduledBGAppRefreshTask.Fix
Run the launch refresh from
.task, which reliably runs once on first appearance. TheonChange(.active)handler stays for genuine background→foreground returns;refreshAll()'sisRefreshingguard makes any overlap a no-op.Verify on device
Fully close the app, change a subscription's configs server-side, then cold-launch — a notification should appear without pulling to refresh.
Note
This fixes the foreground/launch path. Guaranteed delivery while the app is fully closed still depends on
BGAppRefreshTask, which iOS throttles heavily for sideloaded apps — an OS limitation, not a code bug.