OneSignal-Cordova-SDK icon indicating copy to clipboard operation
OneSignal-Cordova-SDK copied to clipboard

[question]: How to retrieve the sent data from notification object?

Open JEricaM opened this issue 1 year ago • 2 comments

How can we help?

Hi to everyone I have integrated OneSignal into my Ionic app (Ionic + StencilJS + vanilla JavaScript) following this guide: https://documentation.onesignal.com/docs/ionic-sdk-setup.

In my app, upon clicking the notification, it is stored on the device by retrieving the relevant data from the notification object in my use case. However, I'm having trouble understanding how to retrieve the date.

This is the object retrieved upon opening the app.

{
    "action": {
        "type": 0
    },
    "notification": {
        "androidNotificationId": 1715699538,
        "groupedNotifications": [],
        "notificationId": "a7322c7e-80da-4406-8354-049c346417e8",
        "templateName": "",
        "templateId": "",
        "title": "title",
        "body": "body",
        "lockScreenVisibility": 1,
        "fromProjectNumber": "866050520933",
        "priority": 5,
        "additionalData": {
            ....
        },
        "rawPayload": "{\"google.delivered_priority\":\"normal\",\"google.sent_time\":1689242144132,\"google.ttl\":259200,\"google.original_priority\":\"normal\",\"custom\":\"{\\\"a\\\":{\\\"notification_url\\\":\\\"\\\\\\/news\\\\\\/2\\\"},\\\"i\\\":\\\"a7322c7e-80da-4406-8354-049c346417e8\\\"}\",\"pri\":\"5\",\"vis\":\"1\",\"from\":\"866050520933\",\"alert\":\"body.\",\"title\":\"title\",\"google.message_id\":\"0:1689242144148610%e0ad9d53f9fd7ecd\",\"google.c.sender.id\":\"866050520933\",\"androidNotificationId\":1715699538}"
    }
}

I assume that if you're on an Android app, you need to retrieve the date by converting the timestamp from google.sent_time. But what about iOS? Since I don't have a way to directly test the app on iOS yet, I wanted to understand what the structure would be in that case, so I know how to map the data.

It seems to me that the date cannot be retrieved from anywhere else, right? I haven't found any information in either the documentation or the OneSignal sending dashboard.

Thanks

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

JEricaM avatar Aug 11 '23 14:08 JEricaM

Still have the problem...

JEricaM avatar Sep 01 '23 07:09 JEricaM

@JEricaM Hello I apologize for the late response are you wanting to get the data when a notification is received/clicked on as described here?

emawby avatar Nov 03 '23 22:11 emawby