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] data message not triggering onMessage on foreground #29714

Closed
kabychow opened this issue Mar 21, 2019 · 3 comments · Fixed by flutter/plugins#1318
Closed

Comments

@kabychow
Copy link

kabychow commented Mar 21, 2019

Everything works perfectly fine when i send a notification message

JSON for notification message:

{
   "priority": "high",
   "notification": {
      "title": "Title",
      "body": "Body"
   },
   "data": {
      "click_action": "FLUTTER_NOTIFICATION_CLICK",
      "another_key": "mydata"
   },
   "to": "<my_fcmtoken>"
}

But onMessage event stops triggering when I send a data message (removing the notification key)

JSON for data message:

{
   "priority": "high",
   "data": {
      "click_action": "FLUTTER_NOTIFICATION_CLICK",
      "another_key": "mydata"
   },
   "to": "<my_fcmtoken>"
}

both getting success=1 from the google fcm response

This issue happens to me on iOS device (I don't have an Android device to test if it happens on Android)
I am using firebase_messaging 4.0.0+1

@ZatacaSystems
Copy link

ZatacaSystems commented Apr 11, 2019

here is the solution @cgfischer @Khaibin

@cgfischer
Copy link

I have the same problem with onMessage not being called on data messages under iOS. In all test cases the Android and iOS flutter app is running in foreground. Messages with the "notification" work fine on both Android and iOS but when I remove the notification element and send just a "data" message, then the iOS application does not receive the onMessage callback.

In my case I am using python on my back-end server to publish notification messages. The python code looks like:

                msg = firebase_messaging.Message(
                    android=firebase_messaging.AndroidConfig(
                        priority='high', ttl=30.0),
                    apns=firebase_messaging.APNSConfig(
                        headers={'apns-priority': '10'}),
                    data=data_message,
                    # notification=firebase_messaging.Notification(
                    #    title='GC Runner data',
                    #    body=data_message['op']),
                    token=fcm_token)
                rc = firebase_messaging.send(msg)

Everything works fine (iOS and Android receive onMessage callback) when the notification parameter is passed into the Message constructor. When I comment out this parameter (as shown) then the iOS app stops receiving the onMessage callback.

Here is my flutter doctor output:

C:\projects\mobile\golfdb>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v1.4.9-hotfix.1, on Microsoft Windows [Version 10.0.17134.706], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.3)
[√] VS Code, 64-bit edition (version 1.33.1)
[√] Connected device (2 available)

• No issues found!

Here is my pubspec.yaml:

C:\projects\mobile\golfdb>type pubspec.yaml
name: golfdb
description: A new Flutter project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+14

environment:
  sdk: ">=2.1.0-dev.5.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  intl: ^0.15.7

  shared_preferences: ^0.4.3
  flutter_secure_storage: ^3.1.2
  device_info: ^0.2.1
  http: ^0.11.3
  cached_network_image: ^0.5.1
  flutter_cache_manager: ^0.2.0
  uuid: ^1.0.3
  charts_flutter: ^0.5.0
  flutter_markdown: ^0.2.0
  path_provider: ^0.4.1
  audioplayers: ^0.7.8
  keyboard_visibility: ^0.5.1

  firebase_core: ^0.3.4
  firebase_messaging: ^4.0.0+3
  firebase_analytics: ^2.1.1+3

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: "^0.7.0"

flutter_icons:
  image_path: "icons/icon-test.png"
  android: true
  ios: true

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
  assets:

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants