Skip to content
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

fix(messaging): Method channel handlers were not created if FirebaseMessaging.instance.* is not invoked beforehand #11447

Merged
merged 5 commits into from Aug 15, 2023

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Aug 10, 2023

Description

For example, imagine we had this setup, and no other FirebaseMessaging API calls. None of the event handlers would ever fire on native platforms. If the line FirebaseMessaging.instance.isAutoInitEnabled is uncommented, they will work because it will instantiate MethodChannelFirebaseMessaging that creates the method channels necessary for them to work.

This PR will always create the method channel handlers before MethodChannelFirebaseMessaging is instantiated.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

  // Uncomment the line below and the event listeners will fire.
  // FirebaseMessaging.instance.isAutoInitEnabled;
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  FirebaseMessaging.onMessage.listen((RemoteMessage message){
    
  });
  FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
    
  });

  runApp(MessagingExampleApp());
}

Related Issues

fixes #11008
fixes #11410
fixes #10043

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@russellwheatley russellwheatley changed the title fix(messaging): Method channels were not created if "FirebaseMessaging.instance.*" is not invoked beforehand fix(messaging): Method channels were not created if FirebaseMessaging.instance.* is not invoked beforehand Aug 10, 2023
@russellwheatley russellwheatley changed the title fix(messaging): Method channels were not created if FirebaseMessaging.instance.* is not invoked beforehand fix(messaging): Method channel handlers were not created if FirebaseMessaging.instance.* is not invoked beforehand Aug 10, 2023
russellwheatley and others added 2 commits August 15, 2023 09:28
…ace/lib/src/platform_interface/platform_interface_messaging.dart

Co-authored-by: Guillaume Bernos <guillaume@bernos.dev>
@russellwheatley russellwheatley merged commit a3a0776 into master Aug 15, 2023
21 checks passed
@russellwheatley russellwheatley deleted the messaging-11008 branch August 15, 2023 15:02
khanliKU pushed a commit to khanliKU/flutterfire that referenced this pull request Aug 18, 2023
…Messaging.instance.*` is not invoked beforehand (firebase#11447)

Co-authored-by: Guillaume Bernos <guillaume@bernos.dev>
exaby73 pushed a commit that referenced this pull request Sep 3, 2023
…Messaging.instance.*` is not invoked beforehand (#11447)

Co-authored-by: Guillaume Bernos <guillaume@bernos.dev>
@firebase firebase locked and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.