fix(ios): add UIScene lifecycle support for Flutter 3.38+#197
Open
henry11996 wants to merge 3 commits intoThexXTURBOXx:masterfrom
Open
fix(ios): add UIScene lifecycle support for Flutter 3.38+#197henry11996 wants to merge 3 commits intoThexXTURBOXx:masterfrom
henry11996 wants to merge 3 commits intoThexXTURBOXx:masterfrom
Conversation
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
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
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:application(_:continue:restorationHandler:)is not called under UIScene — the equivalentscene(_:continueUserActivity:)must be used instead.UIApplication.shared.delegate?.windowandUIApplication.shared.keyWindowreturnnilunder UIScene, causingACQUIRE_ROOT_VIEW_CONTROLLER_FAILEDerrors.Changes
addSceneDelegate:when available (backwards-compatible viaresponds(to:)— older Flutter versions unaffected)scene(_:continueUserActivity:)to handle universal links under UIScene lifecyclehandleUserActivity(_:)to avoid duplicating logic between old and new lifecycleconnectedScenes-based approach, with@available(iOS 15, *)guard forkeyWindowand legacy fallback for old lifecycleVerification
scene(_:continueUserActivity:)matches Flutter'sFlutterSceneLifeCycleDelegateprotocoladdSceneDelegateregistration pattern matchesfirebase_auth's approachkeyWindowusage guarded with@available(iOS 15, *), fallback towindows.first(where:)for iOS 13-14flutter build ios --no-codesign)Related
firebase_auth: https://github.com/firebase/flutterfire/blob/master/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/FLTFirebaseAuthPlugin.mgoogle_mobile_adstracking same issue: [Feature Request] [iOS] Migrate to UIKit's scene-based lifecycle googleads/googleads-mobile-flutter#1391