4

I'm trying to create an app that can receive push notification. The push notifications are sent using AWS SNS and using FCM token rather than Expo's Token. The notifications were received, however, every notification was received twice by the system tray. I tried using a phone without expo installed, but it still received 2 notifications.

this is my payload request when sending to SNS

{
"GCM": "{ \"notification\": { \"text\": \"test message\" } }"
}

Any idea why this is happening? I'm willing to provide the code, however I have no idea which part should I put. Here's one example. The app name is the same, but the first notification has expo's logo in it. update: after sending through firebase console I realized that the notification with expo icon is the correct one.

EDIT: After trying to send a notification from firebase console, I managed to get 1 notification only. Is the problem lies in SNS?

EDIT[2] I took a look at my Cloudwatch Log for the SNS Platform Application. And the NumberOfMessagesPublished metrics suggest that only 1 message published. So I guess it eliminates the possibility that the SNS api was called twice.

EDIT[3] I tried to use go-fcm package to send notification to fcm directly. I got 2 notifications even without using SNS. But why sending notification to fcm directly has a different output than using Firebase console?

enter image description here

UPDATE

Finally, I managed to get it to work by setting a tag field in the notification field to prevent duplicates.

So the payload is like this:

{
"GCM": "{ \"notification\": { \"text\": \"test message\", \"tag\": \"testing\" } }"
}

However this still does not answer the question on why I got the duplicates :(

kkesley
  • 3,258
  • 1
  • 28
  • 55
  • may be from FCM Message content is Sending Twice with Message and Message Content use any one to handle/display Notification.. I my case I got Same but After Hiding Message/ Message Content its fixed – Whats Going On Feb 28 '19 at 11:23
  • how did you fix that? I'm currently using `AWS SNS` to deliver the push notification – kkesley Feb 28 '19 at 11:28
  • share your Notification handler for fcm as example – Whats Going On Feb 28 '19 at 11:29
  • I don't currently have any notification handler anywhere in my code, I just register my FCM token from expo's `yield Notifications.getDevicePushTokenAsync()`, then register it in `AWS SNS`, then send the message from the console – kkesley Feb 28 '19 at 11:32
  • Are you setting the notification token correctly? Have you registered more than 1 token due to perhaps reinstalling the app during development. – Richard Le Mesurier Feb 28 '19 at 13:00
  • 1
    @RichardLeMesurier I associated a userID with a `SNS Endpoint` which is associated with `1 FCM Token`. So I think it won't be a duplicate per user basis. And after further testing, I tried using FCM directly in firebase dashboard instead of `SNS` and the notification was not duplicated when I use firebase dashboard. – kkesley Feb 28 '19 at 22:02
  • Spontaneously I think If you get two Notifications then you have sent two Notifications – Erik May 13 '19 at 17:33
  • Facing the same issue. Note that one notification has the expo icon and other has app icon. Using tag only retains the one with expo icon. Have opened a github issue (https://github.com/expo/expo/issues/4450) – aarjithn Jun 06 '19 at 12:37
  • Also - using tag means there would be ONE notification only at a time (new one replaces old if tag is same). If you doesn't want that to be the case, make sure to not hardcode a tag and instead use something like a timestamp. – aarjithn Jun 06 '19 at 12:39

3 Answers3

0

Do you have your application built and installed in your phone ?

I think that the issue is because you have Expo and "Your App" installed.

If not, I think that you have duplicated the Expo Token. Remember that the best practice for Push Notifications is updating the Expo Token each time that you launch your app.

You cant test your notifications with expo tool. https://expo.io/dashboard/notifications

  • Hi Christobal, Thanks for your answer! Yes, I do have my expo app installed. However, I tried using a phone without expo and it still getting duplicate notification as well.. For the token, I'm using FCM directly with AWS SNS, so, I don't use Expo's token. – kkesley Feb 28 '19 at 21:59
0

Only one app installed, I think this is because Expo catches the notification and creates a new customized one.

I send notification with FCM.

Using a tag "fixes" the double notification issue.

William Desportes
  • 1,412
  • 1
  • 22
  • 31
  • Just wanted to reiterate - using tag means there would be ONE notification only at a time (new one replaces old if tag is same). If you doesn't want that to be the case, make sure to not hardcode a tag and instead use something like a timestamp – aarjithn Oct 17 '19 at 10:07
0

Set the "tag" attribute in the "notification" part of your JSON request.

{
  "to": "xxxxxxxxxxxxxxx",
  "notification": {
      'title': "YOUR TITLE",
      "tag": "GENERATED_UNIQUE_ID",
      'body': "YOUR DESCRIPTION",
      "content_available": "true"
  }
}
Amir Ajorloo
  • 85
  • 1
  • 5