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

firebase_messaging 10.0.2 - FirebaseMessaging.onMessageOpenedApp is never triggered #6483

Closed
kristijorgji opened this issue Jun 26, 2021 · 2 comments
Labels
Needs Attention This issue needs maintainer attention. type: bug Something isn't working

Comments

@kristijorgji
Copy link

kristijorgji commented Jun 26, 2021

Bug report

FirebaseMessaging.onMessageOpenedApp is never triggered, even when I click notification (app is killed), then app opens.
I can see in flutter logs
this is working fine FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

This is never getting executed

FirebaseMessaging.onMessageOpenedApp.listen((message) {
      _logger.d('onMessageOpenedApp: ${message.data}');
      handle(message);
    });

Versions

flutter --version
Flutter 2.2.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d79295af24 (11 days ago) • 2021-06-11 08:56:01 -0700
Engine • revision 91c9fc8fe0
Tools • Dart 2.13.3

firebase_messaging: ^10.0.2

Usage

main.dart

void main() async {
  await _initializeFirebase(config.isProduction);
// below stuff not relevant as we initialise right away firebase

  runZonedGuarded(() {
    runApp(AppConfigWidget(
      config: config,
      child: BlocProvider<AppBloc>(
        create: (context) => appBloc,
        child: App(
          locale: locale,
        ),
      ),
    ));
  },
      config.isProduction
          ? FirebaseCrashlytics.instance.recordError
          : _reportCrash);
}

Future<void> _initializeFirebase(bool isProduction) async {
  await Firebase.initializeApp();
  await FirebaseCrashlytics.instance
      .setCrashlyticsCollectionEnabled(isProduction);
  if (isProduction) {
    // Pass all uncaught errors from the framework to FirebaseCrashlytics.
    Function originalOnError = FlutterError.onError;
    FlutterError.onError = (FlutterErrorDetails errorDetails) async {
      await FirebaseCrashlytics.instance.recordFlutterError(errorDetails);
      // Forward to original handler.
      originalOnError(errorDetails);
    };
  }

  PushNotificationsManager();
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  FirebaseMessaging.onMessageOpenedApp.listen((message) {
   // THIS IS NEVER TRIGGERED!!!
    getLogger('app_runner').d('Firebase.onMessageOpenedApp: ${message.data}');
// The call below does app internal logic, just parses notification data and redirects to other view (which worked fine before //upgrade to 10.0.2
    PushNotificationsManager.handle(message);
  });
}

/// Define a top-level named handler which background/terminated messages will
/// call.
/// To verify things are working, check out the native platform logs, flutter logs
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  getLogger('app_runner').d('Firebase.onBackgroundMessage: ${message.data}');
}

As mentioned _firebaseMessagingBackgroundHandler this works fine !!! when app is closed/killed in flutter logs command the logs appear, but when clicking the notification we expect onMessageOpenedApp.listen callback to run, and to read same notification there, then handle it in our extra class and redirect user to proper view

Also what is difference between getInitialMessage and onMessageOpenedApp

Flutter doctor

flutter doctor -v
[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale en-DE)
    • Flutter version 2.2.2 at /Users/kristi.jorgji/flutter
    • Framework revision d79295af24 (2 weeks ago), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/kristi.jorgji/Library/Android/sdk
    • Platform android-30, build-tools 29.0.3
    • ANDROID_HOME = /Users/kristi.jorgji/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5, Build version 12E262
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.2.3)
    • IntelliJ at /Users/kristi.jorgji/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • SM J510FN (mobile)                 • badea702      • android-arm    • Android 7.1.1 (API 25)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 7.0 (API 24) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 91.0.4472.114

• No issues found!

@kristijorgji kristijorgji added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Jun 26, 2021
@supidupicoder
Copy link

same issue here

@sanyamjain65
Copy link

@kristijorgji I am facing the same issue. Can you please tell me how you solved this?

@firebase firebase locked and limited conversation to collaborators Jul 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Attention This issue needs maintainer attention. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants