Weird data behavior in RNReceivedMessageHandler.js
See original GitHub issueBug
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:
- Created 3 years ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
But the given solution (linked issue) is more safe.
Thanks @Dallas62 . Closed as the problem is caused by deprecated code.