Push Notification Empty Data

Hi,
sorry to say that this is exactly the same as shifto’s issue that was closed a couple of days back.


Although with no conclusion…

So the problem is with empty data!

Unfortunately we can’t use expo’s amazing firebase BE, instead we’ve created our own mega scala push be service…

Although for testing purposes we’ve been using the node-pushnotifications lib.
The message sent from this is:

{
  "sender": "Fantasy Man",
  "userText": "alertId:aZl3kE",
  "data": {
    "alertId": "aZl3kE"
  },
  "aps": {
    "badge": 0,
    "sound": "ping.aiff",
    "alert": {
      "title": "OMG",
      "body": "I can't believe it's working!",
      "payload": {
        "data": {
          "alertId": "aZl3kE"
        }
      }
    },
    "category": "",
    "content-available": 1,
    "thread-id": ""
  }
}

What we get as a notification object from registerNotificationListener is

{
  "remote": true,
  "data":{},
  "actionId": null,
  "userText": null,
  "origin": "selected"
}

Any help would be hugely appreciated!,
Cheers,
Stephen.

// UPDATE
ok after creating a new expo project, ejecting, firing up Xcode and debugging… I’ve come to this conclusion…
To get the data property when not using expo’s PN service (which is awesome …) you have to provide a body property in the root of your message:

{
  "sender": "Fantasy Man",
  "body": {
    "alert-id": "a53fyy"
  },
  "aps": {
    "badge": 0,
    "sound": "ping.aiff",
    "alert": {
      "title": "OMG",
      "body": "I can't believe it's working!",
      "payload": {
         "data":{"alert-id":1234}
      }
    }
  }
}

That body property gets mangled over to data in your js when subscribing to a Notification with

this._notificationSubscription = Notifications.addListener(
      this._handleNotification
    );

The mangling or adaption is done here:

in the properties method at the bottom.

We’d really hoped that the data prop could have been provided either in the payload or as a direct child to the aps section { aps:{data:{alertId:1234}}} of the message.

We can live with putting our app data in the root {body:{shouldBeData:1234}, aps:{}} although somehow, I guess this is by design… but why?

/Stephen.

3 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.