question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird data behavior in RNReceivedMessageHandler.js

See original GitHub issue

Bug

The following code is not fired in RNReceivedMessageHandler.js. The data is null but the data in onNotification is alright.

 JSONObject data = getPushData(notificationData.get("data"));

        if (data != null) { 
            if (!bundle.containsKey("message")) {
                bundle.putString("message", data.optString("alert", null));
            }
            if (!bundle.containsKey("title")) {
                bundle.putString("title", data.optString("title", null));
            }
            if (!bundle.containsKey("sound")) {
                bundle.putString("soundName", data.optString("sound", null));
            }
            if (!bundle.containsKey("color")) {
                bundle.putString("color", data.optString("color", null));
            }

            final int badge = data.optInt("badge", -1);
            if (badge >= 0) {
                ApplicationBadgeHelper.INSTANCE.setApplicationIconBadgeNumber(mFirebaseMessagingService, badge);
            }
        }

Environment info

Library version: 5.1.0

Steps To Reproduce

Testing payload:

{
"registration_ids":["TOKEN"],
"notification": {
    "title": "up 1.43% on the day",
	"image": "https://images.ctfassets.net/oedqce991w59/5uSR94Vu8sbkTDOedtCh69/6e893251f68e4983a0aa64149e8019f4/facebook.jpg?fm=jpg&fl=progressive&fit=pad&w=256"
  },
"data": {
	"destination": "https://www.youtube.com/watch?v=bBAfSPCfxyg",
	"ext": 1,
	"title": "yo",
	"message": "hi message",
	"image": "https://images.ctfassets.net/oedqce991w59/5uSR94Vu8sbkTDOedtCh69/6e893251f68e4983a0aa64149e8019f4/facebook.jpg?fm=jpg&fl=progressive&fit=pad&w=256"
}
}

expected: the notification would set the message from data.

actual: no message set

BTW, is there a way to show data message with localNotification when the APP is closed?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Dallas62commented, Sep 4, 2020

This part of the code is deprecated, now it’s recommended to trigger the notification from the JS side:

https://github.com/zo0r/react-native-push-notification/issues/1570#issuecomment-666310651

I will need to dig into it to remove this part, but not sure the payload you pasted works on ios.

I think now the “valid” format is:

{
  "registration_ids":[TOKEN],
  "notification": {
    "title": "up 1.43% on the day",
  },
  "data": {
    "data": {
	"destination": "https://www.youtube.com/watch?v=bBAfSPCfxyg",
	"ext": 1,
	"title": "yo",
	"alert": "hi message"
    }
  }
}

But the given solution (linked issue) is more safe.

0reactions
fattomhkcommented, Sep 4, 2020

Thanks @Dallas62 . Closed as the problem is caused by deprecated code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Weird React Native Behavior - Stack Overflow
I am reading the database once using a Context Api, and the data shows perfectly in the screen where you view all your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found