Skip to content

Adopt the UIScene life cycle - #25643

Merged
crazytonyli merged 10 commits into
trunkfrom
task/scene-api-adoption
Jun 17, 2026
Merged

crazytonyli merged 10 commits into
trunkfrom
task/scene-api-adoption

Conversation

@crazytonyli

@crazytonyli crazytonyli commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Note

I recommend reviewing this PR commit by commit.

Description

This PR unblocks compiling on Xcode 27. Adopting UIScene lifecycle is required by Xcode 27.

https://developer.apple.com/documentation/technotes/tn3187-migrating-to-the-uikit-scene-based-life-cycle

The main goal here is to adopt the "new" APIs without crashing or regressing the app. The separation between the UI and the app process is still not very clean, but that can be tightened in future PRs.

  1. The app opts into the scene life cycle in code, via application(_:configurationForConnecting:options:) naming WordPressSceneDelegate, instead of a UIApplicationSceneManifest in each of the three target Info.plists. This keeps the delegate class name in one place, and the unit test host's TestingAppDelegate (which doesn't implement it) stays on the legacy life cycle.
  2. Window creation and UI setup move from willFinishLaunching to the first scene connect (showInitialUI). A scene can disconnect and reconnect within one process, so the UI is built once and the existing window is reattached on later connects.
  3. Background launches now run before any window or authenticator exists, so the background notification and account-changed paths are guarded on hasConfiguredInitialUI rather than on window presence.
  4. A notification-tap cold launch now reaches handleNotification in the .background state, so the inactive handler accepts taps there too, matching the existing workaround in the authentication handler.

Testing instructions

The launch and notification paths carry the regression risk:

  • Cold launch while signed out (the sign-in prologue) and signed in (the app UI).
  • Tap a push notification from a cold start, and confirm it navigates to the note instead of opening the default tab.
  • A background launch (silent push, or a share-extension upload finishing) followed by opening the app.

@dangermattic

dangermattic commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ This PR is assigned to the milestone 27.0. This milestone is due in less than 4 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number32689
VersionPR #25643
Bundle IDcom.jetpack.alpha
Commitd144c0a
Installation URL2mh14r538jsp8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number32689
VersionPR #25643
Bundle IDorg.wordpress.alpha
Commitd144c0a
Installation URL3jv3iq36nb8k0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
crazytonyli force-pushed the task/scene-api-handler-extraction branch from a682e3d to e578add Compare June 12, 2026 00:57
@crazytonyli
crazytonyli force-pushed the task/scene-api-adoption branch from 407de0d to 55292c3 Compare June 12, 2026 00:57
@crazytonyli
crazytonyli force-pushed the task/scene-api-handler-extraction branch from e578add to 5e27133 Compare June 12, 2026 01:13
@crazytonyli
crazytonyli force-pushed the task/scene-api-adoption branch 3 times, most recently from 2053576 to 72d621e Compare June 14, 2026 21:34
@crazytonyli
crazytonyli force-pushed the task/scene-api-handler-extraction branch from 5e27133 to 3392e80 Compare June 14, 2026 21:34
@crazytonyli
crazytonyli changed the base branch from task/scene-api-handler-extraction to trunk June 14, 2026 21:36
@crazytonyli
crazytonyli requested a review from jkmassel June 15, 2026 02:21
@crazytonyli crazytonyli added this to the 27.0 milestone Jun 15, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review June 15, 2026 02:22
The app opts into the scene life cycle via
application(_:configurationForConnecting:options:), which names
WordPressSceneDelegate as the scene delegate in one place for all three app
targets instead of three copies of a UIApplicationSceneManifest; the scene
delegate creates the scene-attached window and forwards every scene callback
into the AppDelegate's shared handlers. Window creation moves from
willFinishLaunching to the scene-connect phase, and launch-time URL,
user-activity, and shortcut payloads arrive through UIScene.ConnectionOptions,
routed through the same methods that handle them at runtime, so the
launchOptions plumbing is dead and removed. UITestConfigurator splits into a
process part that stays in willFinishLaunching (UI-test flags must be parsed
before the launch sequence reads them) and a window part applied when the
window is created. The unit test host's TestingAppDelegate doesn't implement
the scene opt-in, so tests keep the legacy life cycle.
AppAppearance.overrideAppearance() and the Home Screen quick action creation
both reach the app's window indirectly (the override style target and the 3D
Touch trait check). Under the scene life cycle the window does not exist until
the scene connects, so these no-opped when left in willFinishLaunching and
runStartupSequence. Move them into showInitialUI alongside the other
window-dependent launch steps.
…nnect

The system can disconnect the app's scene in the background and reconnect it
later in the same process. showInitialUI previously re-ran the full UI
bootstrap on every connect: it created a fresh window while the window manager
stayed bound to the old one (leaving the new key window empty), re-registered
the Apple ID revocation observer, and replaced the authenticator and notice
presenter. The bootstrap now runs exactly once; later connects reattach the
existing window to the new scene. The window manager's missing-window
fatalError is also downgraded to an assertion with a recovery path, since
background launches make it reachable for any unguarded UI path.
Under the scene life cycle, background launches (silent push, background URL
session wake) run with no UI and no authenticator: both are set up at the
first scene connect now. The support-notification handler built UI through
the root view coordinator, and the account-changed handler showed sign-in UI
and touched WordPressAuthenticator.shared, which fatalErrors before
configureWordPressAuthenticator runs. These paths now skip the UI and
observer work when the UI has not been built. The guards key on
hasConfiguredInitialUI rather than window presence, because the windowManager
emergency fallback can create a window while no scene has ever connected.
sceneWillEnterForeground also fires right after the initial scene connect
during a cold launch, unlike the legacy applicationWillEnterForeground, which
re-ran the Jetpack migration eligibility check and emitted its analytics
event twice per launch; the window phase already runs that check via
windowManager.showUI(). The feature flag and remote config refresh is not
skipped though: for a background-launched process, the launch-time refresh
may be hours stale by the time the user first opens the app, and an extra
refresh right after a cold launch is harmless.
A notification-tap cold launch reaches handleNotification while the
application state is still .background under the scene life cycle: the scene
has connected, but the foreground transition hasn't completed. The inactive
handler rejected that state, so the background handler swallowed the tap with
a silent sync and the app opened without navigating to the tapped
notification. The inactive handler now accepts taps in the background state,
matching the existing workaround in the authentication notification handler.
@crazytonyli
crazytonyli force-pushed the task/scene-api-adoption branch from 72d621e to 299066b Compare June 15, 2026 05:42
Comment on lines +20 to +22
guard let windowScene = scene as? UIWindowScene else {
return
}

@jkmassel jkmassel Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
guard let windowScene = scene as? UIWindowScene else {
return
}
guard let windowScene = scene as? UIWindowScene,
session.role == .windowApplication
else {
return
}

There's a fun bug here where AirPlay mirroring can break the window (validated on-device). This fix avoids that, though we might want to revisit it later for better multi-screen support.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I have addressed the issue in a slightly different way in d338794.

configurationForConnecting attached WordPressSceneDelegate to every connecting
scene, so an external-display scene (AirPlay mirroring or a wired display) ran
showInitialUI and reattached the app's single window to that non-interactive
scene, blanking the device's screen. The delegate is now attached only to the
windowApplication scene, and the Info.plists re-declare
UIApplicationSupportsMultipleScenes as false, which was lost when the scene
manifest was replaced with code-based configuration.
@jkmassel

Copy link
Copy Markdown
Contributor

Filed #25664 to track the windowManager scene-less fallback / single-source window creation as a non-blocking follow-up — surfaced while reviewing this.

@jkmassel jkmassel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to potentially cause feature flags to be fetched repeatedly. I filed #25665 to track it, and we should probably address it soon

@crazytonyli
crazytonyli added this pull request to the merge queue Jun 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 17, 2026
@crazytonyli
crazytonyli added this pull request to the merge queue Jun 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 17, 2026
@crazytonyli
crazytonyli added this pull request to the merge queue Jun 17, 2026
Merged via the queue into trunk with commit d393267 Jun 17, 2026
24 checks passed
@crazytonyli
crazytonyli deleted the task/scene-api-adoption branch June 17, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants