EddyVerbruggen / nativescript-local-notifications

:mailbox: NativeScript plugin to easily schedule local notifications
MIT License
162 stars 57 forks source link

Notification won't fire if app is closed #182

Open emperorjm opened 4 years ago

emperorjm commented 4 years ago

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:

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 } });
});

});`

sikemullivan commented 3 years ago

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