Code Monkey home page Code Monkey logo

Comments (8)

russellwheatley avatar russellwheatley commented on July 22, 2024 2

hmmmm, after investigating for some time, I don't think there is anything we can do about this. The problem is; we receive the RemoteMessage here, but when the user taps the notification, we receive the intent here.

The intent contains the following in the extras:

{
	notificationId: 123456,
	payload: ""
}

This does not allow us to tie the message received with the notification tapped (notificationId is not a property on the RemoteMessage when the message is received). This is different to when the message is received in the background. Here is the documentation

This specific part:
Screenshot 2024-06-12 at 12 19 01

The data is not contained within the intent itself when the message is received in the foreground. Therefore, we have no way of knowing what the initial message is.

Your best bet might be to use data-only messages and handle the notifications yourself rather than use firebase messaging to handle the notifications.

from flutterfire.

russellwheatley avatar russellwheatley commented on July 22, 2024 1

@cogivn - I mean you might consider using data-only messages to trigger a notification using another Flutter plugin (such as flutter_local_notifications). Presumably they don't have the same limitation on android when the message is received in the foreground.

from flutterfire.

TarekkMA avatar TarekkMA commented on July 22, 2024

Hi @cogivn ,

Thank you for your submission and for taking the time to provide detailed information about the issue. We will look into it and get back to you

from flutterfire.

russellwheatley avatar russellwheatley commented on July 22, 2024

I wasn't able to reproduce. Here is how you can test:

  1. Run app in release i.e. flutter run --release.
  2. Terminate app (it will still be running when in release mode).
  3. Send message (I use nodjs admin SDK. See here)
  4. Open app via notification and print out the message returned from getInitialMessage() .

So I had a print here in firebase_messaging example app:

FirebaseMessaging.instance.getInitialMessage().then(
  (value) => setState(
    () {
      print('${value?.data.toString()}');
      _resolved = true;
      initialMessage = value?.data.toString();
    },
  ),
);

and here are the logs from console:

Flutter run key commands.
h List all available interactive commands.
c Clear the screen
q Quit (terminate the application on the device).
I/flutter (21076): Handling a background message 0:1718036389166773%50d7604150d76041
I/flutter (21076): {foo: bar, float: 12034}
I/flutter (21076): FCM Token: dEUSTNftSGmTqpr2TeKx

I sent this in my nodejs admin script:

admin
  .messaging()
  .send(
    {
      token: androidToken,
      data: {
        foo: 'bar',
        float: '12034'
      },
      notification: {
        title: 'A great title',
        body: 'Great content',
      },
      android: {
        // Required for background/terminated app state messages on Android
        priority: 'high',
      },
      apns: {
        payload: {
          aps: {
            // Required for background/terminated app state messages on iOS
            contentAvailable: true,
          },
        },
      },
    },
  )

you can see the data is:

      data: {
        foo: 'bar',
        float: '12034'
      },

from flutterfire.

cogivn avatar cogivn commented on July 22, 2024

I wasn't able to reproduce. Here is how you can test:

  1. Run app in release i.e. flutter run --release.
  2. Terminate app (it will still be running when in release mode).
  3. Send message (I use nodjs admin SDK. See here)
  4. Open app via notification and print out the message returned from getInitialMessage() .

So I had a print here in firebase_messaging example app:

FirebaseMessaging.instance.getInitialMessage().then(
  (value) => setState(
    () {
      print('${value?.data.toString()}');
      _resolved = true;
      initialMessage = value?.data.toString();
    },
  ),
);

and here are the logs from console:

Flutter run key commands.
h List all available interactive commands.
c Clear the screen
q Quit (terminate the application on the device).
I/flutter (21076): Handling a background message 0:1718036389166773%50d7604150d76041
I/flutter (21076): {foo: bar, float: 12034}
I/flutter (21076): FCM Token: dEUSTNftSGmTqpr2TeKx

I sent this in my nodejs admin script:

admin
  .messaging()
  .send(
    {
      token: androidToken,
      data: {
        foo: 'bar',
        float: '12034'
      },
      notification: {
        title: 'A great title',
        body: 'Great content',
      },
      android: {
        // Required for background/terminated app state messages on Android
        priority: 'high',
      },
      apns: {
        payload: {
          aps: {
            // Required for background/terminated app state messages on iOS
            contentAvailable: true,
          },
        },
      },
    },
  )

you can see the data is:

      data: {
        foo: 'bar',
        float: '12034'
      },

Hi @russellwheatley,

please swap the step 2 and 3 like this:

  1. Send message when app in foreground(displayed the notification but do not tap into notification)
  2. Kill app (Terminate app)
  3. Tap into notification to launch the app again.

from flutterfire.

Poloten avatar Poloten commented on July 22, 2024

I get the same bug, FirebaseMessaging.instance.getInitialMessage() return null.

Reprodeced only on ios (test on 16.7.8)
If I send 2 notification, and click one of them it's work for first and second notification.

Maybe in documentation lost some information about AppDelegete.swift to configure or smt else ?

from flutterfire.

russellwheatley avatar russellwheatley commented on July 22, 2024

Hey @cogivn - I was able to reproduce, I'll see what can be done to fix this issue 👍

from flutterfire.

cogivn avatar cogivn commented on July 22, 2024

Hi @russellwheatley,

Would be grateful if you could elaborate on the use of data-only messages as a potential solution to this issue. While I understand that notification handling for both notification messages and data-only messages is likely required when app is in foreground on the Android platform, the problem appears to persist even when a user taps on a notification after the application has been terminated.

from flutterfire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.