Skip to content

docs(uiscene): remind to call super when overriding SceneDelegate met… - #14067

Open
sumit-2007-git wants to merge 3 commits into
flutter:mainfrom
sumit-2007-git:fix/uiscene-delegate-super-call
Open

sumit-2007-git wants to merge 3 commits into
flutter:mainfrom
sumit-2007-git:fix/uiscene-delegate-super-call

Conversation

@sumit-2007-git

@sumit-2007-git sumit-2007-git commented Nov 12, 2026 •

Copy link
Copy Markdown

Updates the "Create a SceneDelegate" section in sites/docs/src/content/release/breaking-changes/uiscenedelegate.md to show overriding sceneDidBecomeActive with a super call (in both Swift and Objective-C) and adds an :::important callout reminding developers to call super when overriding UISceneDelegate methods implemented by FlutterSceneDelegate so callbacks continue forwarding to Flutter and plugins.

Fixes #14042

@sumit-2007-git
sumit-2007-git requested review from a team and sfshaza2 as code owners November 12, 2026 05:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the uiscenedelegate.md documentation to demonstrate how to override sceneDidBecomeActive in Swift and Objective-C, and adds a warning about calling super in overridden lifecycle methods. The review feedback recommends calling the superclass implementation at the beginning of the overridden methods to ensure proper initialization. Additionally, it suggests clarifying the warning note, as calling super on methods not implemented by FlutterSceneDelegate would cause compilation errors in Swift or runtime crashes in Objective-C.

Comment on lines +291 to +297
class SceneDelegate: FlutterSceneDelegate {
override func sceneDidBecomeActive(_ scene: UIScene) {
// Custom logic here.

super.sceneDidBecomeActive(scene)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In UIKit lifecycle methods, it is standard practice to call the superclass implementation (super) at the beginning of the method. This ensures that the superclass (and consequently Flutter/plugins) completes its activation process before any custom subclass logic executes, which is especially important if your custom logic relies on services or plugins that expect the scene to be fully active.

Suggested change
class SceneDelegate: FlutterSceneDelegate {
override func sceneDidBecomeActive(_ scene: UIScene) {
// Custom logic here.
super.sceneDidBecomeActive(scene)
}
}
class SceneDelegate: FlutterSceneDelegate {
override func sceneDidBecomeActive(_ scene: UIScene) {
super.sceneDidBecomeActive(scene)
// Custom logic here.
}
}

Comment on lines +320 to +324
- (void)sceneDidBecomeActive:(UIScene *)scene {
// Custom logic here.

[super sceneDidBecomeActive:scene];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the Swift implementation, it is standard practice in Objective-C to call [super sceneDidBecomeActive:scene] at the beginning of the method to ensure the superclass is fully initialized and active before running custom logic.

Suggested change
- (void)sceneDidBecomeActive:(UIScene *)scene {
// Custom logic here.
[super sceneDidBecomeActive:scene];
}
- (void)sceneDidBecomeActive:(UIScene *)scene {
[super sceneDidBecomeActive:scene];
// Custom logic here.
}

Comment on lines +333 to +335
If you override any `UISceneDelegate` lifecycle methods,
always call `super` so `FlutterSceneDelegate` continues
forwarding scene callbacks to Flutter and plugins.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling super on a method that the superclass does not implement will cause a compilation error in Swift (since there is no method to override) or a runtime crash in Objective-C (unrecognized selector sent to instance). Since FlutterSceneDelegate only implements a subset of UISceneDelegate methods, the warning should be clarified to refer only to the methods implemented by FlutterSceneDelegate rather than 'any' UISceneDelegate lifecycle methods.

Suggested change
If you override any `UISceneDelegate` lifecycle methods,
always call `super` so `FlutterSceneDelegate` continues
forwarding scene callbacks to Flutter and plugins.
If you override any of the UISceneDelegate methods
implemented by FlutterSceneDelegate,
always call super so FlutterSceneDelegate continues
forwarding scene callbacks to Flutter and plugins.
References
  1. Report an issue only if the change introduces or worsens it, it's of medium severity or higher, and you can state its concrete consequence. Include the problem, its consequence, and the smallest useful fix. (link)

@MuthuGCodes

Copy link
Copy Markdown
Contributor

/gcbrun

@flutter-website-bot

Copy link
Copy Markdown
Collaborator

Staged preview of the updated docs.flutter.dev site (updated for commit af87317):

https://flutter-docs-prod--docs-pr14067-fix-uiscene-delegate-s-hfet2apu.web.app

@MuthuGCodes MuthuGCodes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sumit-2007-git! Thanks for creating this PR.

I wanted to share a couple of things:

  1. Please add the PR description, and possibly Fixes #14042 if this PR is intended to fix this issue #14042 .
  2. In the `:::important` note, please remove the second sentence (`Calling super on a protocol method...`) so the callout stays concise."

`FlutterSceneDelegate` implements (such as `sceneDidBecomeActive`),
always call `super` so `FlutterSceneDelegate` continues
forwarding scene callbacks to Flutter and plugins.
Calling `super` on a protocol method not implemented by

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can drop this sentence "Calling super on a protocol method ... selector exception in Objective-C."

@sumit-2007-git

Copy link
Copy Markdown
Author

Thanks for the review, @MuthuGCodes! Both items are now addressed:

  1. Updated the PR description and added Fixes #14042.
  2. Removed the second sentence from the :::important callout in 21125eb to keep it concise.

Ready for another look whenever you have a moment!

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.

Improve the "Create a SceneDelegate" by indicating you must call super at the end of overriden methods

3 participants