Skip to content

fix(ios): resolve rootViewController from connected UIWindowScene (fixes launch crash under UIScene lifecycle) - #323

Open
vingulati wants to merge 1 commit into
cybex-dev:masterfrom
Payssurance:scene-lifecycle-fix
Open

vingulati wants to merge 1 commit into
cybex-dev:masterfrom
Payssurance:scene-lifecycle-fix

Conversation

@vingulati

Copy link
Copy Markdown

Problem

On the modern Flutter iOS template (Flutter ≥ 3.35, which uses the UIScene lifecycle — a SceneDelegate extending FlutterSceneDelegate + a UIApplicationSceneManifest), UIApplication.shared.delegate.window is always nil because the window is owned by the scene, not the app delegate.

SwiftTwilioVoicePlugin.init() does:

let appDelegate = UIApplication.shared.delegate
guard let controller = appDelegate?.window??.rootViewController as? FlutterViewController else {
    fatalError("rootViewController is not type FlutterViewController")
}

Because appDelegate.window is nil, this fatalErrors during plugin registration — crashing the entire host app at launch, before any Dart runs. Stack trace bottoms out at SwiftTwilioVoicePlugin.init()register(with:)GeneratedPluginRegistrantdidInitializeImplicitFlutterEngine.

Fix

Resolve the window from UIApplication.shared.connectedScenes when the app delegate has no window, and — since the method/event channels are also wired in register(with:)degrade gracefully (return) instead of fatalError if the root view controller isn't attached yet during registration.

No behavior change for classic (non-scene) apps: appDelegate.window is used first when present.

Testing

Reproduced the launch crash on a Flutter 3.44.7 app using the UIScene template (iOS 26 simulator). With this change the host app launches normally and the plugin's channels work. Verified against tag 0.3.2+2.

🤖 Generated with Claude Code

…cle)

The modern Flutter iOS template uses the UIScene lifecycle, so
UIApplication.shared.delegate.window is nil and the plugin's init()
fatalErrors ('rootViewController is not type FlutterViewController'),
crashing the host app at launch during plugin registration.

Resolve the window from UIApplication.connectedScenes when the app
delegate has none, and skip the redundant init-time channel wiring
(also done in register(with:)) instead of crashing.
@cybex-dev

Copy link
Copy Markdown
Owner

Hi @vingulati,

thank you for your contribution though this has already been fixed by PR #320 merged yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants