nativescript-local-notifications icon indicating copy to clipboard operation
nativescript-local-notifications copied to clipboard

Notification won't fire if app is closed

Open emperorjm opened this issue 5 years ago • 1 comments
trafficstars

I am using the https://market.nativescript.org/plugins/nativescript-laravel-echo plugin to receive broadcasts from my WebSocket server and while the app is loaded I am able to receive the broadcast and trigger the notification which works. This works whether the app is loaded in the foreground or background.

Once I close the app it's not able to receive the broadcast and generate the notification. I am looking at the firebase solution which generates a token which would allow for this I believe but this solution is a lot cleaner and way lot easier to use so I am wondering if this plugin can accommodate my use case.

Setup:

  • Nativescript Vue (2.4.0)
  • Vue (2.6.10)
  • Android 10

Code:

`import { TnsEcho } from 'nativescript-laravel-echo'; import { LocalNotifications } from "nativescript-local-notifications";

const options = { key: 'oyraytsytgd', wsHost: '178.65.34.27', wsPort: 6001, disableStats: true, broadcaster: 'pusher', // socket.io, pusher };

let Echo = new TnsEcho(options); Echo.channel('payment').listen('Payment', e => { console.log(e); LocalNotifications.schedule([{ title: 'You have a new Payment Request', body: 'A user is requesting a payment, bigTextStyle: false, forceShowWhenInForeground: true, at: new Date(new Date().getTime() + (5 * 1000)), // 5 seconds from now }]);

LocalNotifications.addOnMessageReceivedCallback(notificationData => {
    this.$navigateTo(Payment, { props: { id: e.id } });
});

});`

emperorjm avatar Feb 13 '20 06:02 emperorjm

When the application is closed, your websocket is also closed. I would imagine you need to switch to a push notification.

sikemullivan avatar Jun 07 '21 22:06 sikemullivan