allboatsrise / expo-marketingcloudsdk

Expo module for Salesforce Marketing Cloud SDK
MIT License
12 stars 12 forks source link

[ANDROID ONLY]: Push Notification sent from Marketing cloud is not displayed when app is in KILLED state. #45

Closed PallabJS closed 1 month ago

PallabJS commented 1 month ago

When push notification is sent from MarketingCloud - MobilePush, Notification is not displayed when app is at closed or Quit state. I found out that Salesforce is not sending notification part in the notification payload, instead it's sending data, which might be getting ignore by the firebase notification handler.

messaging().setBackgroundMessageHandler(async (nf) => {
    console.log("BG Notification: ", JSON.stringify(nf, null, 2));
  });

And looks like there is no way to configure the payload at MobilePush service to include notification object. Found a thread that exactly matches the current scenario -> https://salesforce.stackexchange.com/questions/330974/android-mobile-push-via-marketingcloudsdk-not-received

After going through the code I observed that the troubleshoot fix step is already added in the code.

image

But still I am not able to see notification when App is in KILLED state.

FYI: In all other cases, notification works perfectly fine.

Any Ideas?

andrejpavlovic commented 1 month ago

Try sending the push notification directly from firebase. Usually the issue I've seen is that the push notification doesn't appear when the app is running, not the other way around.

PallabJS commented 1 month ago

Yes, the push notification won't appear when App is in Foreground, that is a separate thing from what I am facing. Sending push notification from firebase works as it add notification field to the payload. But when sending a push notification from Salesforce MobilePush service, the payload won't include the notification field, and firebase background handler seems to ignore it as a data-only only type notification, hence notification is not displayed. I needed a work around for this particular case.

andrejpavlovic commented 1 month ago

What does your javascript code look like? Are you following the instructions on how to set the push token as per https://github.com/allboatsrise/expo-marketingcloudsdk/blob/c3b465b99dd4750669b3cd45983f690b5890a67d/README.md?plain=1#L41-L93 ?

Not sure what workaround you're referring to, push notifications work just fine on iOS/Android with this expo plugin. Make sure you have latest expo, expo-notification packages. Etc.

PallabJS commented 1 month ago

Solved this issue by completely removing @react-native-firebase/messaging from the project. Using multiple notification handling services caused the incoming notification at KILLED state to be handled by firebase which treats data-only notification as silent/no-show notification.

andrejpavlovic commented 1 month ago

Makes sense, good work!