Skip to content

[UIScene] Using implicit engine misses willConnectScene event #186547

Closed

Description

@hellohuanlin

Steps to reproduce

This came up when reading:

// When using an implicit FlutterEngine, created by the FlutterViewController in another
// ViewController, we expect plugins to be registered after the FlutterViewController is
// created, which results in the `application:didFinishLaunchingWithOptions:` and
// `scene:willConnectToSession:options:` events being missed. This is not a expected use case
// but it could be utilized.

For didFinishLaunching

The old behavior before UIScene migration is that, if FlutterViewController is created programmatically, even if it's created as child of the rootVC (like what this integration test is doing), plugins still won't receive didFinishLaunching event, because rootVC's viewDidLoad is called after didFinishLaunching returns.

However, if FlutterViewController is created from storyboard (again, as child of the rootVC), plugins will receive didFinishLaunching event.

This behavior is odd, but since it's been this way, we should keep it untouched.

For sceneWillConnect

First of all, there's no original behavior before UIScene migration (sceneWillConnect is only applicable after UIScene migration)

From my observation, the current behavior for FlutterViewController created as the child of the rootVC:

  • If FlutterViewController is created programmatically:
    • If engine is created in app delegate's didFinishLaunching, plugins will receive sceneWillConnect
    • If engine is created afterwards, plugins won't receive sceneWillConnect
  • If FlutterViewController is created from Storyboard, then plugins will always receive sceneWillConnect.

(for both cases above, FlutterViewController is created as a child of the rootVC)

This behavior is a bit confusing and can be brittle:

  • If a developer makes FlutterViewController a child of the rootVC, the intention is to receive sceneWillConnect, regardless whether they use storyboard or not.
  • The fact that Apple changed storyboard loading order once (and caused so much headache) hinted that the current setup is quite brittle, and could very well cause more headache down the road.

Proposal

The only factor that matters here is: "when is FlutterViewController added to the scene?" - if it's added in the same run-loop as scene connection, we should pipe sceneWillConnect; if it's added afterwards, we should not pipe sceneWillConnect. Using storyboard or not should be irrelevant.

In this particular case, where a developer makes FlutterViewController a child of the rootVC, we should always pipe sceneWillConnect, regardless of using storyboard or not.

Why not just check if VC is added before sceneWillConnect is called?

Because for some scenarios (e.g. SwiftUI), VC is added after sceneWillConnect is called. But it still happens in the same run-loop.

Can we just use scene connection's notification?

Note that scene connection notification is sent after sceneWillConnect is called, but before viewDidLoad of rootVC is called. So if we rely on the notification will also miss some edge cases.

The simplest approach is to rely on willEnterForeground and didEnterBackground, which is called after view is loaded, which is the best timing to capture this edge case. The drawback would be that it's called with a delay. However, it's still on the same run-loop (just like the connection notification path).

Activity

  1. saurabh-mirajkar commented on May 18, 2026

    @saurabh-mirajkar
    Contributor

    @hellohuanlin Thanks for the report. Routing to team-ios to investigate further.

  2. added
    platform-iosiOS applications specifically
    team-iosOwned by iOS platform team
    and removed
    in triagePresently being triaged by the triage team
    on May 18, 2026
  3. vashworth commented on May 18, 2026

    @vashworth
    Contributor

    I can't remember if this was actually a problem or just a use case I added tests for. We should test it without the UIScene migration to see if pre-UIScene received the didFinishLaunching event. If it didn't, then I think we can just close this.

  4. hellohuanlin commented on May 18, 2026

    @hellohuanlin
    ContributorAuthor

    I can't remember if this was actually a problem or just a use case I added tests for. We should test it without the UIScene migration to see if pre-UIScene received the didFinishLaunching event. If it didn't, then I think we can just close this.

    In pre-UIScene, when using storyboard, FlutterViewController is loaded before didFinishLaunching is called. See the first 2 diagrams from: https://docs.google.com/document/d/1ZfcQOs-UKRa9jsFG84-MTFeibZTLKCvPQLxF2eskx44/edit?tab=t.0

    Oh I may have looked at the wrong case - you are talking about the non-storyboard case.

  5. changed the title [-][UIScene] Using implicit engine misses didFinishLaunching & willConnectScene events[/-] [+][UIScene] Using implicit engine misses willConnectScene event[/+] on May 19, 2026
  6. hellohuanlin commented on May 19, 2026

    @hellohuanlin
    ContributorAuthor

    We should test it without the UIScene migration to see if pre-UIScene received the didFinishLaunching event.

    @vashworth I tried out the pre-migration behavior, and confirmed didFinishLaunching is not called in this case. Though sceneWillConnect is another story (as there was no "pre-migration" behavior), and I find the current behavior a bit confusing and can be brittle. I updated the issue with more info.

  7. added
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    on May 21, 2026
  8. 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.

  9. 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