Open sachinGAcharya opened 5 years ago
As far as I know, Mobile apps can not execute anything while the app is killed.
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.
@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);
@sachinGAcharya Let me know if you figure out something to do when app is killed, so i can also use it.
Thanks
@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
@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.
@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.
@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?
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.
But How the alaram app works with the snooze option
No idea. All I can tell you is what Apple does.
Then there is no solution to snooze the alarm for 5 min when the app is killed or removed from background right?
Not easily with JavaScript. You may be able to do that with other plugins or Objective-C or Java.
There is any plugin like local notification to customization of java or objective c
@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
@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
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.