Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Started bridging the scene delegate to the lifecycle delegate for shortcuts #170180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
Loading
from

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Jun 6, 2025

testing: There integration tests in the plugins repo.
fixes: #169928

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added platform-ios iOS applications specifically engine flutter/engine repository. See also e: labels. team-ios Owned by iOS platform team labels Jun 6, 2025

@interface FlutterAppDelegate ()

@property(nonatomic, strong, nullable) FlutterPluginAppLifeCycleDelegate* lifeCycleDelegate;
Copy link
Member

@jmagman jmagman Jun 6, 2025

Choose a reason for hiding this comment

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

keep the readwrite implementation property as-is, add readonly to this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the direct usage of the lifecycle delegate and instead started calling directly into the app delegate as we discussed in our meeting. That's a bit more scary but I think it technically is the safer thing to do.

Copy link
Contributor

@hellohuanlin hellohuanlin Jun 6, 2025

Choose a reason for hiding this comment

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

could you share a bit more details (for me and future readers) on app delegate vs life cycle delegate decision? Thx!

Copy link
Member Author

Choose a reason for hiding this comment

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

Jenn pointed out that users could be subclassing FlutterAppDelegate and override application:performActionForShortcutItem:completionHandler: and be performing their own logic, like say analytics for the usage of shortcuts.

Talking directly the the lifecycle delegate would break them, but fix the plugin problems. So, I decided to call the delegate directly.

@gaaclarke
Copy link
Member Author

quick actions tested locally (since the test won't run as part of presubmit), it works:

Screenshot 2025-06-06 at 3 16 22 PM

@gaaclarke gaaclarke marked this pull request as ready for review June 6, 2025 22:17
@gaaclarke gaaclarke requested a review from a team as a code owner June 6, 2025 22:17
@gaaclarke gaaclarke requested review from jmagman and vashworth June 6, 2025 22:17
Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

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

looks reasonable. can we add some unit tests?

@gaaclarke
Copy link
Member Author

looks reasonable. can we add some unit tests?

We have integration tests. We can't add unit tests because it relies on the application delegate being a FlutterAppDelegate which we don't support in our unit test harness.

@hellohuanlin
Copy link
Contributor

We can't add unit tests because it relies on the application delegate being a FlutterAppDelegate which we don't support in our unit test harness.

Could you explain more? OCMock should be able to mock the app delegate (I may misunderstand the problem tho).

id mockApplication = OCMClassMock([UIApplication class]);
OCMStub([mockApplication shared]).andReturn(mockApplication);
id mockAppDelegate = OCMClassMock([FlutterAppDelegate class]);
OCMStub([mockApplication delegate]).andReturn(mockApplication)

@gaaclarke
Copy link
Member Author

Could you explain more? OCMock should be able to mock the app delegate (I may misunderstand the problem tho).

Thanks, I forgot you could mock like that. Done.

@gaaclarke gaaclarke requested a review from hellohuanlin June 9, 2025 20:35
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2025
Copy link
Contributor

auto-submit bot commented Jun 9, 2025

autosubmit label was removed for flutter/flutter/170180, because - The status or check suite Linux gradle_plugin_fat_apk_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gaaclarke
Copy link
Member Author

rerunning Linux gradle_plugin_fat_apk_test, issue filed

@gaaclarke
Copy link
Member Author

@hellohuanlin friendly ping

Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

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

I have some concerns around relaying scene delegate calls to app delegate, mainly the fact that we are changing Apple's behavior that may surprise us in the future. See more details here: #170037 (comment)

If there's no other way around, I'm fine with relaying the calls, but just wanna hear your thoughts on it first.

if ([appDelegate isKindOfClass:[FlutterAppDelegate class]]) {
[appDelegate application:FlutterSharedApplication.application
performActionForShortcutItem:shortcutItem
completionHandler:completionHandler];
Copy link
Contributor

Choose a reason for hiding this comment

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

If we do it for one method, we should probably do it for all methods for minimal surprise.

Copy link
Member Author

Choose a reason for hiding this comment

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

This method is special where apple has specifically called out that they will not call the old app delegate method. Things like "will resign active" are still called. The goal of this PR is to fix broken behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Things like "will resign active" are still called.

IIRC from my experiment a few days ago, "will resign active" are not called

Copy link
Contributor

@hellohuanlin hellohuanlin Jun 10, 2025

Choose a reason for hiding this comment

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

Same as "background/foreground" callbacks (there are some discussions around it a few days ago in the chat channel)

Copy link
Contributor

Choose a reason for hiding this comment

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

Related: #170178

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should be test driven. I don't think we have any failing tests related to resign active. We should double check, but I think that should be addressed in a different PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

also reported in #170037

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that should be addressed in a different PR.

Either way sounds good to me. I just wanna have a consistent behavior - if we relay 1 call, we should relay all similar calls.

@AquaGeek
Copy link

AquaGeek commented Jun 10, 2025

I have some concerns around relaying scene delegate calls to app delegate, mainly the fact that we are changing Apple's behavior that may surprise us in the future. See more details here: #170037 (comment)

If there's no other way around, I'm fine with relaying the calls, but just wanna hear your thoughts on it first.

I agree. This feels like the kind of thing that addresses the short-term pain of everyone having to move their code to the scene delegate (or add the relay to their own code) but will create headaches long-term. I would much rather see Flutter take the stance that code should be moved to align with platform expectations.

Another approach would be to spin up a subclass that does the relaying. Teams that don't want that functionality would simply use the superclass instead.

@gaaclarke
Copy link
Member Author

but will create headaches long-term.

@AquaGeek what headaches are you thinking of? Can you explain further?

@gaaclarke
Copy link
Member Author

I have some concerns around relaying scene delegate calls to app delegate, mainly the fact that we are changing Apple's behavior that may surprise us in the future. See more details here: #170037 (comment)

If there's no other way around, I'm fine with relaying the calls, but just wanna hear your thoughts on it first.

@hellohuanlin What do you see the alternative being?

Here's the options I see:

  1. Update the migration guide
  2. Bridge FlutterSceneDelegate to FlutterAppDelegate (current state of PR)
  3. Duplicate the logic from FlutterAppDelegate in FlutterSceneDelegate (original state of PR)

We chose to do 2 because 3 could end up breaking users without any runtime help. I'm not quite sure what the problem we are trying to avoid is. I think there is just a general sense that maybe something bad can happen, but I couldn't think of one. All of this happens under the hood and we can swap it around if we want.

@hellohuanlin
Copy link
Contributor

I think there is just a general sense that maybe something bad can happen, but I couldn't think of one.

This resonate with my last paragraph in #170037 (comment)

Here's the options I see...

Maybe it is the least worst option we have (unless we can think of a better option?)

I'm not against this. I just wanna make sure we are aware of this departure of apple's practice, and get it well documented if we do so.

@gaaclarke gaaclarke requested a review from hellohuanlin June 11, 2025 15:23
@gaaclarke
Copy link
Member Author

I switched back to talking the the lifecycle delegate directly. While I think in general we should make our decisions based on concrete concerns and tests, not calling the FlutterAppDelegate isn't technically a breaking change even if it can break some customers. So, I'm fine doing the more reserved solution of talking to the delegate directly.

Keeping the logic inline with Apple's will be more understandable at least for the odd scenarios where it may matter.

@hellohuanlin
Copy link
Contributor

What do you think about we firstly start with relaying the calls, and adding the warning in tooling against app delegate usage (apple's deprecation warning isn't sufficient as we discussed yesterday), and then remove the relay in the future? This allows a smoother transition for developers.

@gaaclarke
Copy link
Member Author

What do you think about we firstly start with relaying the calls, and adding the warning in tooling against app delegate usage (apple's deprecation warning isn't sufficient as we discussed yesterday), and then remove the relay in the future? This allows a smoother transition for developers.

I don't think it's necessary. The people this effects is low, there is no longer an automatic migration and and it's not a Breaking Change. I think that will just complicate the migration. Who knows what decision will be made in the future but migrating may never be an automatic thing considering the events of the last few days. I plan on filing an issue for the static warning like we discussed yesterday as part of resolving this PR, so that idea doesn't get lost.

@hellohuanlin
Copy link
Contributor

Sounds good. I think i'm comfortable with this. Before stamping this, @jmagman FYI this reverts to the original implementation that you had concerns: #170180 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine flutter/engine repository. See also e: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS] Quick Actions Not Triggered When App is in Background
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.