Skip to content

[UIScene] last minute sceneWillConnect registration is missing corner cases #185688

Closed

Description

@hellohuanlin

Here's the code that auto-registers an engine at the last minute:

if ([scene.delegate conformsToProtocol:@protocol(UIWindowSceneDelegate)]) {
NSObject<UIWindowSceneDelegate>* sceneDelegate =
(NSObject<UIWindowSceneDelegate>*)scene.delegate;
if ([sceneDelegate.window.rootViewController isKindOfClass:[FlutterViewController class]]) {
FlutterViewController* rootViewController =
(FlutterViewController*)sceneDelegate.window.rootViewController;
[self addFlutterManagedEngine:rootViewController.engine];
}
}

My understanding is that, this code is in-place because the engine hasn't been added to the listeners list when sceneWillConnect is called, So it performs a workaround at last minute, to see if the rootVC is a FlutterVC, and if so, registers the engine.

This is missing corner cases when FlutterVC isn't the rootVC.

Note that this is for multi-scene scenario.

Activity

  1. added
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    on Apr 30, 2026
  2. vashworth commented on May 1, 2026

    @vashworth
    Contributor

    Single scene apps are always registered here:

    - (void)sceneWillConnect:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
    UIScene* scene = notification.object;
    if (!FlutterSharedApplication.application.supportsMultipleScenes) {
    // Since there is only one scene, we can assume that the FlutterEngine is within this scene and
    // register it to the scene.
    // The FlutterEngine needs to be registered with the scene when the scene connects in order for
    // plugins to receive the `scene:willConnectToSession:options` event.
    // If we want to support multi-window on iPad later, we may need to add a way for deveopers to
    // register their FlutterEngine to the scene manually during this event.
    FlutterPluginSceneLifeCycleDelegate* sceneLifeCycleDelegate =
    [FlutterPluginSceneLifeCycleDelegate fromScene:scene];
    if (sceneLifeCycleDelegate != nil) {
    return [sceneLifeCycleDelegate engine:self receivedConnectNotificationFor:scene];
    }
    }
    }

    I don't think there are any edge-cases that don't get hit here. If you can think of any, feel free to re-open.

  3. hellohuanlin commented on May 1, 2026

    @hellohuanlin
    ContributorAuthor

    @vashworth Did i mis-read the intention of this code? My understanding is that this code is in-place to handle missing registration at last minute, and the rootVC check here is missing corner cases (but maybe this is not for single scene scenarios?):

    if ([scene.delegate conformsToProtocol:@protocol(UIWindowSceneDelegate)]) {
    NSObject<UIWindowSceneDelegate>* sceneDelegate =
    (NSObject<UIWindowSceneDelegate>*)scene.delegate;
    if ([sceneDelegate.window.rootViewController isKindOfClass:[FlutterViewController class]]) {
    FlutterViewController* rootViewController =
    (FlutterViewController*)sceneDelegate.window.rootViewController;
    [self addFlutterManagedEngine:rootViewController.engine];
    }
    }

  4. changed the title [-][UIScene] For single scene setup, plugins may still miss `sceneWillConnect` delegate calls[/-] [+][UIScene] Plugins may still miss `sceneWillConnect` delegate calls in some cases[/+] on May 1, 2026
  5. changed the title [-][UIScene] Plugins may still miss `sceneWillConnect` delegate calls in some cases[/-] [+][UIScene] last minute `sceneWillConnect` registration is missing corner cases[/+] on May 1, 2026
  6. hellohuanlin commented on May 1, 2026

    @hellohuanlin
    ContributorAuthor

    Ok I updated the wording of the issue, but still pending clarification on #185688 (comment)

    Re-openning

  7. vashworth commented on May 1, 2026

    @vashworth
    Contributor

    My understanding is that this code is in-place to handle missing registration at last minute, and the rootVC check here is missing corner cases (but maybe this is not for single scene scenarios?):

    This is only for multi-scene. Single scene is handled by the code I mentioned above

  8. hellohuanlin commented on May 1, 2026

    @hellohuanlin
    ContributorAuthor

    My understanding is that this code is in-place to handle missing registration at last minute, and the rootVC check here is missing corner cases (but maybe this is not for single scene scenarios?):

    This is only for multi-scene. Single scene is handled by the code I mentioned above

    Gotcha. I assumed this code was for single scene because the guide says:

    When multiple scenes is enabled (UIApplicationSupportsMultipleScenes), Flutter can't automatically associate a FlutterEngine with a scene during the scene connection phase.

    So this is actually inaccurate, as it does indeed associate for multi-scenes too, but only for some cases.

    Cross linking to flutter/website#13344 for website update

  9. github-actions commented on Oct 30, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions