eclipsesource / tabris-plugin-firebase

A firebase plugin for Tabris.js
https://tabrisjs.com
BSD 3-Clause "New" or "Revised" License
6 stars 5 forks source link

Guidance : how to receive custom data #35

Closed natanraj closed 6 years ago

natanraj commented 6 years ago

Planning to send a notification using firebase. It is successfully received at device. So far no issue. i want some guidance how to get the below discount key value (10), when i click the notification from system tray.

The below is sent from node.js server using FCM.

var message = { to: regKey, // required fill with device token or topics data: { discount: 10 }, notification:{ title:'New Users ? Avail 10% discount', body: 'Time is running, avail your offer now' } };

Expected behavior

App is opened when I click the notification on system tray (android), but i want to capture the 'discount' key value in my first index.js

firebase.Messaging.on('message', function(data){ localStorage.setItem('pushNoteData', JSON.stringify(data)); });

I was expecting my localStorage being set with the data i sent from server. But it is not set. Any guidance on what am I missing.

mpost commented 6 years ago

In your example you are creating a notification message. Please create a data message as outlined here: https://github.com/eclipsesource/tabris-plugin-firebase/blob/master/doc/cloud-messaging.md#send-message-with-notification-from-server

natanraj commented 6 years ago

I followed this. But i need a notification as well, when the app is on the background (like it appears on system tray) so that the user clicks on the app to launch. It all seems so simple, may be i am missing something.

mpost commented 6 years ago

Please make sure to only include the data field. In it you can have the title and body fields. See the docs for an example.

natanraj commented 6 years ago

Thanks. It works. I had raised another issue on the same. Using both i am able to solve the problem now. #34

natanraj commented 6 years ago

Closing this. Thanks