Is it possible to catch a callback on click event when application is removed from memory ?
Same issue here. When the app is in memory, the click event is triggered just fine. When the app is not running (not even in background), I am able to open the app by clicking the notification, but the event is never triggered.
@neshke89 @intellitour same problem here! Any progress for you guys? I really need this behavior for iOS, as the app frequently drops out of the background state.
Not sure if anyone's still interested, but I've gotten closer to the root cause of this (in iOS at the very least).
I found that the notification was firing correctly, and then correctly being added to the eventQueue
. However, when I added some logging around the eventQueue being executed, I found this:
<Warning>: EVALUATING EVENT IN QUEUE
<Warning>: cordova.plugins.notification.local.core.fireEvent('click', { notification data..},'background')
<Warning>: EVALUATING EVENT IN QUEUE
<Warning>: cordova.plugins.notification.local.core.fireEvent('cancel', { notification data.. },'background')
<Warning>: Debug: app - handling deviceready event
That last line was our app actually being ready to handle events. Granted, we use Kendo, which takes a bit longer to initialize, but I realized that the events were firing before the app had a chance to deal with them.
I don't have a permanent fix for now, but I made this change in local-notification-util.js and I'm now able to catch the click event even when coming from a completely killed state!
channel.deviceready.subscribe(function () {
// Device is ready now, the listeners are registered
// and all queued events can be executed.
setTimeout(function(){exec(null, null, 'LocalNotification', 'deviceready', []);}, 5000);
});
Thanks @bromeostasis !
I took a slightly different approach by exposing
exec(null, null, 'LocalNotification', 'deviceready', []);
in the API and manually calling it in my code when the device is definitively ready. I still don't find it a good solution, but it may be a bit more robust by not being timing-dependent.
Still, your hint got me there, thanks a lot!
Most helpful comment
Not sure if anyone's still interested, but I've gotten closer to the root cause of this (in iOS at the very least).
I found that the notification was firing correctly, and then correctly being added to the
eventQueue
. However, when I added some logging around the eventQueue being executed, I found this:That last line was our app actually being ready to handle events. Granted, we use Kendo, which takes a bit longer to initialize, but I realized that the events were firing before the app had a chance to deal with them.
I don't have a permanent fix for now, but I made this change in local-notification-util.js and I'm now able to catch the click event even when coming from a completely killed state!