I have to schedule two local notifications in my ionic 3 mobile app. These notifications need to be 1 hour apart from each other. For example: if first notification is sent out at 3:00 pm then the second local notification should be sent out at 4:00 pm.
Can someone suggest a way of getting the time at which first notification was triggered so that I can add 1 hour to it and schedule the second notification.
Thanks in advance. SKR
You can use the local notifications plugin here:
https://ionicframework.com/docs/native/local-notifications/
use the schedule method like so:
this.localNotifications.schedule({
id: 1,
text: 'Single Immediate ILocalNotification',
sound: isAndroid? 'file://sound.mp3': 'file://beep.caf',
data: { secret:'hi' }
});
let originalTime = new Date().getTime();
// Schedule delayed notification (1 hour from original time)
this.localNotifications.schedule({
id: 2,
text: 'Delayed 1 hour ILocalNotification',
at: new Date(originalTime + 3600000), // 3600000 is 1 hour in milliseconds
sound: isAndroid? 'file://sound.mp3': 'file://beep.caf',
data: { secret:'hi 1 hour later' }
});