Skip to content

fix(ios): add UIScene lifecycle support for Flutter 3.38+#197

Open
henry11996 wants to merge 3 commits intoThexXTURBOXx:masterfrom
henry11996:fix/ios-uiscene-lifecycle
Open

fix(ios): add UIScene lifecycle support for Flutter 3.38+#197
henry11996 wants to merge 3 commits intoThexXTURBOXx:masterfrom
henry11996:fix/ios-uiscene-lifecycle

Conversation

@henry11996
Copy link
Copy Markdown

Summary

Flutter 3.38+ introduced UIScene-based lifecycle as the recommended pattern for iOS apps (migration guide). Apple has announced that UIScene lifecycle will be required in a future iOS release after iOS 26.

This plugin currently only registers via addApplicationDelegate, which causes two issues under the UIScene lifecycle:

  1. Universal links broken: application(_:continue:restorationHandler:) is not called under UIScene — the equivalent scene(_:continueUserActivity:) must be used instead.
  2. Root view controller lookup fails: UIApplication.shared.delegate?.window and UIApplication.shared.keyWindow return nil under UIScene, causing ACQUIRE_ROOT_VIEW_CONTROLLER_FAILED errors.

Changes

  • Register with addSceneDelegate: when available (backwards-compatible via responds(to:) — older Flutter versions unaffected)
  • Add scene(_:continueUserActivity:) to handle universal links under UIScene lifecycle
  • Extract shared handleUserActivity(_:) to avoid duplicating logic between old and new lifecycle
  • Replace deprecated root view controller lookup with connectedScenes-based approach, with @available(iOS 15, *) guard for keyWindow and legacy fallback for old lifecycle

Verification

  • Method signature scene(_:continueUserActivity:) matches Flutter's FlutterSceneLifeCycleDelegate protocol
  • addSceneDelegate registration pattern matches firebase_auth's approach
  • keyWindow usage guarded with @available(iOS 15, *), fallback to windows.first(where:) for iOS 13-14
  • Example project builds successfully (flutter build ios --no-codesign)
  • Backwards compatible — old lifecycle path preserved

Related

Flutter 3.38+ introduced UIScene-based lifecycle as the recommended
pattern for iOS apps (see https://docs.flutter.dev/release/breaking-changes/uiscenedelegate).
Apps that adopt this pattern no longer route lifecycle events through
UIApplicationDelegate — they use UISceneDelegate instead.

This plugin previously only registered via `addApplicationDelegate`,
which meant:

1. `application(_:continue:restorationHandler:)` for universal links
   would never be called under the UIScene lifecycle.
2. Root view controller lookup used deprecated APIs
   (`UIApplication.shared.delegate?.window`, `keyWindow`) that return
   nil under the UIScene lifecycle.

Changes:

- Register with `addSceneDelegate` when available (backwards-compatible
  via `responds(to:)` check, so older Flutter versions are unaffected)
- Add `scene(_:continue:)` to handle universal links under UIScene
- Extract shared `handleUserActivity` to avoid duplicating logic
- Replace deprecated root view controller lookup with
  `connectedScenes`-based approach, with legacy fallback
@henry11996 henry11996 closed this Apr 19, 2026
@henry11996 henry11996 reopened this Apr 24, 2026
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.

1 participant