Skip to content

[firebase_messaging] Both onMessage and onLaunch called with same gcm.message_id #1911

@RabbitKabong

Description

@RabbitKabong

Describe the bug
After sending a notification via google-api-php-client to GCM, I receive the same message twice on a device: both onMessage and onLaunch are triggered with the same gcm.message_id.

To Reproduce
Steps to reproduce the behavior:

  1. Send message to an individual iPhone 11 device (with its token or using a topic) via google-api-php-client:
["message"]=>
  array(6) {
    ["token"]=>
    string(152) "<TOKEN>"
    ["notification"]=>
    array(2) {
      ["title"]=>
      string(12) "<TITLE>"
      ["body"]=>
      string(48) "<BODY>"
    }
    ["data"]=>
    array(5) {
      ["category"]=>
      string(7) "<CATEGORY>"
      ["type"]=>
      string(16) "<TYPE>"
      ["title"]=>
      string(33) "<TITLE>"
      ["url"]=>
      string(62) "<URL>"
      ["id"]=>
      string(4) "<ID>"
    }
    ["apns"]=>
    array(1) {
      ["payload"]=>
      array(1) {
        ["aps"]=>
        array(2) {
          ["sound"]=>
          string(7) "default"
          ["content-available"]=>
          int(1)
        }
      }
    }
    ["android"]=>
    array(2) {
      ["priority"]=>
      string(4) "HIGH"
      ["notification"]=>
      array(2) {
        ["click_action"]=>
        string(26) "FLUTTER_NOTIFICATION_CLICK"
        ["sound"]=>
        string(7) "default"
      }
    }
    ["fcm_options"]=>
    array(1) {
      ["analytics_label"]=>
      string(16) "<LABEL>"
    }
  }
  1. With my app closed, when I tap on the notification in iOS, the same message is handled by the device twice. Here's what's comes in the log in Console:

onMessage

flutter: FCM: onMessage: {category: <CATEGORY>, google.c.a.e: 1, id: <ID>, aps: {alert: {title: <TITLE>, body: <BODY>}, sound: default, content-available: 1.0}, title: <TITLE>, type: <TYPE>, google.c.a.m_l: <CATEGORY>, gcm.message_id: 1580433692277472, url: <URL>}

onLaunch

flutter: FCM: onLaunch: {category: <CATEGORY>, google.c.a.e: 1, id: <ID>, aps: {alert: {title: <TITLE>, body: <BODY>}, sound: default, content-available: 1.0}, title: <TITLE>, type: <TYPE>, google.c.a.m_l: <CATEGORY>, gcm.message_id: 1580433692277472, url: <URL>}

Expected behavior
With the app closed, I'd expect to see onLaunch processed by the app, and not onMessage.

Additional context
I'm using firebase_core ^0.4.3+1, firebase_messaging ^6.0.9, and firebase_analytics ^5.0.9 in my app at the moment.

I haven't been able to reproduce this issue in the iOS Simulator, Android simulator, or on an Android device. I haven't been able to reproduce this on several other iOS devices I have access to, either. Unsubscribing from notifications (via unsubscribeFromTopic()), reinstalling the app, and then resubscribing didn't make a difference.

Not sure if it matters, but the two devices I can replicate this on were both recently upgraded and migrated from older iPhones.

Here's the code snippets I use to handle the notifications:

    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> m) async {
        debugPrint('FCM: onMessage: $m');
        m['messageType'] = 'onMessage';
        _handleFCMMessage(m);
      },
      onLaunch: (Map<String, dynamic> m) async {
        debugPrint('FCM: onLaunch: $m');
        m['messageType'] = 'onLaunch';
        _handleFCMMessage(m);
      },
      onResume: (Map<String, dynamic> m) async {
        debugPrint('FCM: onResume: $m');
        m['messageType'] = 'onResume';
        _handleFCMMessage(m);
      },
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleIssue with no recent activityimpact: customerA bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)plugin: messagingtype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions