NativeScript Firebase Notification Callback Issue

409 views Asked by At

I have an application written in NativeScript. I use Firebase plugin for push notifications. The first problem is that when a device is in the background or it's killed I can't receive any notifications (sending only data parameter) but when I open the app then notification is generating.

The second problem is that when I try to send a push notification (the app is killed) with notification and data parameter the local notification is generating correctly but the callback is executed on notification click, not in the background (my view has not been updated by new data).

Here is part of NativeScript code:

firebase.init({
   onMessageReceivedCallback: (message: Message) => {
     console.log(`Title: ${message.title}`);
     console.log(`Body: ${message.body}`);
     console.log(`Data: ${message.data}`);
     const data = message.data;
     const action = data.action;
     // STORE RESERVATION
     if (action === ItemConstants.STORE_RESERVATION) {
        const item = this.prepareOnlineData(data);
        const result = this.databaseService.saveReservation(item);
        if (result !== -1) {
            console.log("Saved to local database!");
            } else {
                    console.log("Error occurred!");
              }
        }
        // DENY RESERVATION
        if (action === ItemConstants.DENY_RESERVATION) {
           this.databaseService.setReservationStatus(
              ItemConstants.STATUS_DENIED, data.tracking_id
           ).then(result => {
                   console.log(result);
             }, error => {
                   console.log(error);
                });
            }
        }
    }).catch(error => {});

and the part of PHP code that calls Google Service:

$fields = array(
        'to' => $to,
        'notification' => [
            'title' => 'reservation title',
            'body'  => 'you have new reservation',
            'sound' => 'default'
        ],
        'data' => $data,
        'priority' => 'high',
        'delay_while_idle ' => true
    );
// calling curl - google services.

Does anyone have an idea how to fix this issue?

0

There are 0 answers