katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.56k stars 1.75k forks source link

cordova.plugins.notification.local.on not triggering when the app is killed #1682

Open sachinGAcharya opened 5 years ago

sachinGAcharya commented 5 years ago

When the app is in the foreground this event cordova.plugins.notification.local.on() will trigger when I clicked on the notification. But when the app is killed/removed from the background if I click on notification this event is not triggering, Please help me.

Update

I am using local notification as an alarm. It is working fine, But when the user clicks on snooze I Have to snooze alarm for 10 min.How can I do It.This feeture I hav seen in many mobile app.This works when the app is killed also.

va1bhav commented 5 years ago

As far as I know, Mobile apps can not execute anything while the app is killed.

sachinGAcharya commented 5 years ago

I am using local notification as an alarm. It is working fine, But when the user clicks on snooze I Have to snooze alarm for 10 min.How can I do It.This feeture I hav seen in many mobile app.This works when the app is killed also.

va1bhav commented 5 years ago

@sachinGAcharya Run this code before you schedule notification: NOTE: This SNOOZE works only if app is running in foreground/background.


cordova.plugins.notification.local.on('SNOOZE', function (notification, eopts) { if (notification.actions[0].identifier === 'SNOOZE') { var localtime = new Date(); var newId = Date.parse(localtime); localtime = localtime.setMinutes(localtime.getMinutes() + 5); cordova.plugins.notification.local.schedule([{ id: newId, title: notification.title, text: notification.text, foreground : true, at: localtime, priority: 2, actions: [ { id: 'SNOOZE', title: 'SNOOZE', identifier: 'SNOOZE' } ], badge : 1 }]);
} });


use this to schedule notification


cordova.plugins.notification.local.schedule([ { id: $scope.id, data: type, title: title, text: desc, foreground: true, progressBar: { enabled : false, value : timeStamp }, actions: [ { id: 'SNOOZE', title: 'SNOOZE', identifier: 'SNOOZE' } ], trigger: { firstAt: new Date(timeStamp), every : parseInt($scope.reminderInterval), unit : reminderUnit, count: 100 }, badge : 1 } ], succesCallback);


va1bhav commented 5 years ago

@sachinGAcharya Let me know if you figure out something to do when app is killed, so i can also use it.

Thanks

sachinGAcharya commented 5 years ago

@va1bhav cordova.plugins.notification.local.on where to put this code in app.component.ts constructor ?or in my cureent page.I am using ionic 3

rwillett commented 5 years ago

@va1bhav

That's not quite correct right, whilst a killed app cannot execute anything (its killed), clicking on a notification should start the app up. You can attach data to the payload of the notification so that when the app starts up, it will then go to the right 'screen' in the application.

sachinGAcharya commented 5 years ago

@va1bhav Ya but In normal alaram app user will just click on snooze.It snoozes app without launching the app.How can I acheive this,Thanks for the code.But It will only work when the app is in forground.I need to snooze the alaram for 10 min without launching the app.

va1bhav commented 5 years ago

@rwillett Thank you for the response Rob. Could you please help with resolution for below scenario?

I schedule a notification with "SNOOZE" action item and kill the app, now the notification is received and user taps on "SNOOZE" action item. Now I do not need to launch the app in foreground for this, so how do I run the app in background and execute code for snooze?

rwillett commented 5 years ago

You can't easily. Android might allow a bit of time to run in the background, but IOS won't. Apple is hyper aggressive in backgrounding an app to save battery.

sachinGAcharya commented 5 years ago

But How the alaram app works with the snooze option

rwillett commented 5 years ago

No idea. All I can tell you is what Apple does.

sachinGAcharya commented 5 years ago

Then there is no solution to snooze the alarm for 5 min when the app is killed or removed from background right?

rwillett commented 5 years ago

Not easily with JavaScript. You may be able to do that with other plugins or Objective-C or Java.

Prasand-altius commented 4 years ago

There is any plugin like local notification to customization of java or objective c

StefanRein commented 4 years ago

https://github.com/katzer/cordova-plugin-local-notifications/issues/1798#issuecomment-656962391

akhilashok7539 commented 2 years ago

@sachinGAcharya Run this code before you schedule notification: NOTE: This SNOOZE works only if app is running in foreground/background.

cordova.plugins.notification.local.on('SNOOZE', function (notification, eopts) { if (notification.actions[0].identifier === 'SNOOZE') { var localtime = new Date(); var newId = Date.parse(localtime); localtime = localtime.setMinutes(localtime.getMinutes() + 5); cordova.plugins.notification.local.schedule([{ id: newId, title: notification.title, text: notification.text, foreground : true, at: localtime, priority: 2, actions: [ { id: 'SNOOZE', title: 'SNOOZE', identifier: 'SNOOZE' } ], badge : 1 }]); } });

use this to schedule notification

cordova.plugins.notification.local.schedule([ { id: $scope.id, data: type, title: title, text: desc, foreground: true, progressBar: { enabled : false, value : timeStamp }, actions: [ { id: 'SNOOZE', title: 'SNOOZE', identifier: 'SNOOZE' } ], trigger: { firstAt: new Date(timeStamp), every : parseInt($scope.reminderInterval), unit : reminderUnit, count: 100 }, badge : 1 } ], succesCallback);

the code doesnt work can you please share those function code

akhilashok7539 commented 2 years ago

@va1bhav Ya but In normal alaram app user will just click on snooze.It snoozes app without launching the app.How can I acheive this,Thanks for the code.But It will only work when the app is in forground.I need to snooze the alaram for 10 min without launching the app.

hi can you please share the code for snooze feature