6

I've integrated OneSignal sdk to my react-native project, everything seems to be working fine, except when we add a Title to the push message the android receives a double push notification. When we send the push notification without the title, the android receives one(as intended). Any advise is greatly appreciated.

EDIT:

My code:

// App.js

OneSignal.setAppId("my-app-id");

//Method for handling notifications received while app in foreground

OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent => 
{
  let notification = notificationReceivedEvent.getNotification();
  const data = notification.additionalData
  notificationReceivedEvent.complete(notification);
});

//Method for handling notifications opened
OneSignal.setNotificationOpenedHandler(notification => {
  console.log("OneSignal: notification opened:", notification);
});

I send the push notification through the dashboard - app.onesignal.com by creating a new push notification.

nika
  • 77
  • 2
  • 6
  • 20
  • have you followed this? https://documentation.onesignal.com/docs/duplicated-notifications – Haritha Senevirathne Oct 20 '22 at 18:20
  • @HarithaSenevirathne, yes I have read this documentation, but it doesn't explain why the android receives 2 notifications only if we include the Title in the message, when we send message without a title the android receives only 1 notification. – nika Oct 20 '22 at 18:25
  • I'm going blind over here mate. Can you share your code please where you initiate and send the push notification? – Haritha Senevirathne Oct 20 '22 at 18:39
  • @HarithaSenevirathne, edited my post to include the OneSIgnal initi code, I followed these exact steps https://documentation.onesignal.com/docs/react-native-sdk-setup – nika Oct 20 '22 at 18:54
  • are you using both android and iOS? If so does this happens for both? – Haritha Senevirathne Oct 22 '22 at 12:52
  • @HarithaSenevirathne, it doesn't happen on ios and on android it only happens if I add a title to the message. If the push notification is sent without a title, android receives just 1 notification, if I add title then android receives duplicate. – nika Oct 22 '22 at 16:25
  • what is the onesignal version you are using? – Haritha Senevirathne Oct 23 '22 at 02:49
  • check this https://github.com/OneSignal/OneSignal-Android-SDK/issues/1419 Try using – Haritha Senevirathne Oct 23 '22 at 02:58
  • @HarithaSenevirathne, thank you for sharing that post, I've readbit and I don't think it's the same issue.in my case the android gets duplocate only if a **title** is included into the message, otherwise the messages are not duplicated. – nika Oct 23 '22 at 15:32
  • This means, both FCM and OneSignal is processing your notification. Maybe try disabling each one. – Lawrence Gimenez Oct 29 '22 at 13:14

1 Answers1

-1

Usually duplicate notifications occur due to sending the same push data multiple times. If you see multiple notifications sent in your Delivery Tab with the same message, check your server code that API requests are not repeated with retries or other code errors.

If you are moving to OneSignal and continue to send push from a previous messaging system, this can also cause duplicates and you should discontinue sending from the previous messaging system when you start sending from OneSignal.

Android: If using versions 4.4.1 - 4.6.2 of the Android Native SDK, update to 4.6.3 or higher.

Check to make sure you don't have another push notification plugin/SDK in your app as it could be trying to parse the OneSignal notification, showing it twice. Our Android SDKs prevent duplicate notifications by checking the notification payload for OneSignal specific data.

Android devices with 2 copies of the app installed on the device can also receive duplicate notifications. This could happen if you have a production and staging / dev app installed at the same time with different Android package names. This would result in two different player_ids and two different push tokens.

You can long press on each notification to ensure they are coming from the same app.