double push notification created with React Native + Expo + FCM

怎甘沉沦 提交于 2019-12-10 15:34:40

问题


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?

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 :(


回答1:


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




回答2:


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.




回答3:


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"
  }
}


来源:https://stackoverflow.com/questions/54923807/double-push-notification-created-with-react-native-expo-fcm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!