FlutterFlow / flutterflow-issues

A community issue tracker for FlutterFlow.
98 stars 17 forks source link

Duplicate Push Notifications #2844

Open quindelin opened 2 weeks ago

quindelin commented 2 weeks ago

Has your issue been reported?

Current Behavior

I had push notifications working fine for a while, but recently when I've been pushing a notification to iOS devices, they've been recieving two at the same time: one with data (photo) and one without. They come at the same time.

Expected Behavior

One push notification appears in iOS Notification Center.

Steps to Reproduce

Trigger push notification with data, such as a photo or parameters.

Reproducible from Blank

Bug Report Code (Required)

ITFfzcrlx49Om+EA0a6Jbe1GlmIXQmEcTOURiO0bFDsdF4iuPOxzac+kPxFWTteiS1VlKEWGinoewPDthvzpJvYBEyurc4Q9+cx6dQ3dRTq/aoSoPJaKXkFTL8RjfGqj06eFuiVQKs9vSXdm2EyMfO6vYDHUNYP7Zwh9f6PHaOI=

Context

It's effected my users by them receiving two notifications rather than one.

Visual documentation

Going through more documentation, this is a backend issue, specifically with the sendUserPushNotificationsTrigger cloud function that gets published when I deploy push notifications from FlutterFlow. Here is the issue within index.js:

Notice in the function that the fields of the notification goes into the notification field, rather than the data field. This is causing the duplicate issue, I believe.

for (let i = 0; i < tokensArr.length; i += 500) {
    const tokensBatch = tokensArr.slice(i, Math.min(i + 500, tokensArr.length));
    const messages = {
      notification: {
        title,
        body,
        ...(imageUrl && { imageUrl: imageUrl }),
      },
      data: {
        initialPageName,
        parameterData
      },
      android: {
        notification: {
          ...(sound && { sound: sound }),
        },
      },
      apns: {
        payload: {
          aps: {
            ...(sound && { sound: sound }),
          },
        },
      },
      tokens: tokensBatch,
    };
    messageBatches.push(messages);
  }

Additional Info

Screenshot 2024-04-30 at 10 07 29 AM

See described fix in Stack Overflow.

Environment

- FlutterFlow version: 4.1.45+
- Platform: MacOS Desktop
- Browser name and version: Chrome latest version
- Operating system and version affected: MacOS latest version

General

Relative to the time the changes were made, data was lost within

When following my steps to reproduce, data loss happens

ignalauret commented 2 weeks ago

Hey @quindelin thanks for your report. I'm sorry about your notifications being sent twice. Our technical team is going to take a look into it and keep you updated on this thread. In the meanwhile, could you provide a little bit more information to help them:

Thanks for your help, looking forward for your extra info for our technical team. Have a great day!

quindelin commented 2 weeks ago

@ignalauret Thanks. I'm sending a photo, two page parameters, a title, and some text in my the notification. I'm sending the notification from the Trigger Push Notification action in FlutterFlow, on the ChatPage in my project. The bug code for the widget is linked in the ticket.

https://stackoverflow.com/questions/67820474/double-notifications-in-flutter-firebase-messaging is the thread where I read about this fix. The issue only occurs with messages that have data in them, such as parameters, from what I can surmise in the JavaScript above. Not sure if it's happening for Android, I've only been able to test / see the issue with iOS, but considering the cloud function acts the same for both operating systems, they should also have the same issues.

So it looks like there needs to be a conditional in the JavaScript that handles whether the message has parameters, then everything goes into the data payload, and if not, then it gets sent into the message payload.

ignalauret commented 2 weeks ago

Thanks for the extra information. Now our technical team will take a look at it and keep you updated.

github-actions[bot] commented 3 days ago

This issue is stale because it has been open for 7 days with no activity. If there are no further updates, a team member will close the issue.