Currently, I have a timer implemented in my Ionic3 application. The timer functions smoothly with a setInterval method; however, it poses an issue when the App is put into sleep mode as the timer stops running. Upon reopening the App and bringing it to the foreground, the timer does resume, but it picks up from where it left off before pausing.
I am seeking advice on how to prevent the timer from halting when the App is sent to the background.
This is part of my component:
time: any;
displayTime() {
this.time = moment().hour(0).minute(0).second(this.counter++).format('HH : mm : ss');
}
startTime() {
if(this.runClock == null) {
this.runClock = setInterval(() => {
this.displayTime();
},1000)
}
}
The time display in my HTML is called using {{ time }}
.
Unfortunately, utilizing plugins like https://ionicframework.com/docs/native/background-mode/ is not an option since Apps incorporating this plugin may face rejection by the App Store.
Are there any alternative suggestions to address this issue?