I'm trying to generate (many, too many) local notifications from time to time, but due to the amount of notifications, I make them one by one, generating the first one, and with the trigger event, generating the next one, so that the application doesn't crash. It works fine while the application is open, but when you move to the background, the trigger event stops working. I tried the cordova-plugin-background-mode plugin but it still doesn't work. Is there a solution?
cordova -v): 6.5.0cordova platform ls): ios 4.3.1When a local confirmation is triggered, the following must be generated with the trigger event
When you move to the background, no trigger event is triggered, therefore future local notifications are not generated.
document.addEventListener('deviceready', function () {
cordova.plugins.notification.local.on("trigger",function(notificacion,b){
var datos_alerta={
id: 1,
title: "a title 2",
text: "a text 2",
trigger:{
at: //some date in the future
}
};
cordova.plugins.notification.local.schedule(datos_alerta);
});
cordova.plugins.notification.local.schedule({
id: 1,
title: "a title",
text: "a text",
trigger:{
at://some date in the future
}
});
});
I need to generate a local notification every time one is run, to update it with a new time
I'm also trying to use events to register actions from the user (like delaying a reminder), but sometimes it works, sometimes it doesn't. I suppose the times it works, it does because the app is not truly in background.
Also, if I manually close the app and click the action, it won't work at all.
Trigger events don't seem to work.
If you need lots and lots of notifications when the app is not running, you'll need to go to something like OneSignal, Firebase or PushWoosh. OneSignal is free and works very well.
@rwillett In my case the action event should trigger some updates in-app. Basically, actions are not reliable?
We cannot recall getting any events being triggered when the app is in the background and a user clicks on a local notification. It's not clear to me what should happen under IOS so this might be the right behaviour (or it might not).
Our app is mainly server driven, so we use PushWoosh to send notifications and use local notifications for non-server based information. We use a mixture of silent notifications and text based notifications both from PushWoosh.
It sounds as if you are using local notifications as a scheduling mechanism which might not be the best way to use them.
It may not be that events are not reliable but that they are not supposed to work that way on IOS.
Rob
Dont schedule notifications within a trigger event. The OS will only invoke the event if the app is running in foreground.
@rwillett @katzer Actually I'm not rescheduling/scheduling more notifications based on notifications triggers. What I'm trying to do is get notifications actions to do something in the app. So assuming it wont work in background, is there a way to force actions to always open the app when touched?
Otherwise.. what's the point of actions?
@ammichael
Is an action the same as an event to you? Are we talking about the same thing.
@rwillett I thought 'event' could be the notification trigger and/or actions, no?
AFAIK actions are not the same as events.
An event is what happens when something triggers, e.g. a notification is scheduled triggers an event, the fact that a user has clicked on a notification should trigger an 'event' (though that doesn't seem to work).
It appears that an action is a user defined thing that happens when the user does something specific to a notification. It may well be that an action triggers an event deep down. These are new to local notifications.
You seem to be mixing the two up in your comments and title.
It appears that IOS events do not trigger when the app is in the background. I do not know why, @katzer might be able to explain. I have not used actions as they aren't of interest to me.
If you click on a local notification, it should open the app. It doesn't seem to pass the payload of the local notification but it should open the app.
We happen to be doing some testing on notifications, both local and server based to check it all works after some major rework on other parts of the system.
We have just scheduled a local notification to be sent 90 secs in the future. We then terminated the IOS app,
The local notification appeared. We click on the local notification (no actions), it fires the app up. The app was NOT in the background but was terminated. It all works as expected for selecting the app.
We do not check for events,
@ammichael
See here https://github.com/katzer/cordova-plugin-local-notifications#properties-1. Use the launch property for actions.
As mentioned you need to add launch: true to the action-properties.
And you should check launchDetails at every App-Start to recognise if the App was started by a local-notification (or one of its actions).
launchDetails does hold the notification-id and the event name (your action-id).
If you set the notification-id by yourself and need to recognise it later, be sure to use an 32-bit Integer.
Same issue with beta version in IOS please replicate this issue.
Thanks In advance
This is iOS system behaviour and out of control by the plugin.
Please read the docs for each platform: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html
I am closing this since its not related to the plugin.
My notification is getting scheduled but my click and trigger event is not working using local notification plugin .
Please help
I am using this plugin to send notifications. My app schedules the notification and click and trigger events also working, the notification is also pushed without problems.
BUT
The actions are working only when the app is working in _foreground_.
@katzer How can I open my app when an action is selected. I used launch: true option, but that is not working.
Android : 9, One UI, Samsung Galaxy A10
Plugin version : 0.9.0-beta.2
Most helpful comment
As mentioned you need to add
launch: trueto the action-properties.And you should check launchDetails at every App-Start to recognise if the App was started by a local-notification (or one of its actions).
launchDetailsdoes hold the notification-id and the event name (your action-id).If you set the notification-id by yourself and need to recognise it later, be sure to use an 32-bit Integer.