react-native-background-timer
react-native-background-timer copied to clipboard
BackgroundTimer.stopBackgroundTimer() not stopping timer in iOS
Hello!
I checked all the other issues related with this and the problem still persists in iOS:
componentDidMount
if (Platform.OS === 'android') {
this.interval = BackgroundTimer.setInterval(() => {
this.recurrentTask();
}, 1000);
} else {
BackgroundTimer.runBackgroundTimer(() => {
this.recurrentTask();
}, 1000);
}
componentwillUnmount
if (Platform.OS === 'android') {
BackgroundTimer.clearInterval(this.interval);
} else {
BackgroundTimer.stopBackgroundTimer();
}
It works perfectly in Android but in iOS the timer doesn't stop. I tried the same approach from Android in iOS, which works but not when the app is in background, and I also tried the "Crossplatform" which also doesn't work. This means that the timer is not being released in iOS.
RN version: 0.58.4 react-native-background-timer version: 2.1.1
that correct... not stops in iOs and in android
that correct... not stops in iOs and in android
@LuisBonsembiante In Android it works perfectly for me. Android 8.1
In the beginning It looks like it works, but if you close the app and wait 30 - 60 minutes, you will see the battery is drain cause problem with release the wake lock.
If someone know how to release it, it will be very helpful.
I also look at the code and it looks like it should free it, but most of the time is not release it.
In the beginning It looks like it works, but if you close the app and wait 30 - 60 minutes, you will see the battery is drain cause problem with release the wake lock.
If someone know how to release it, it will be very helpful.
I also look at the code and it looks like it should free it, but most of the time is not release it.
@roysG Thanks for your comment. I'm only testing with 1min, 3min and 5min in background. For those timespans, well I think there is no solution. The SO is free to even kill the app: https://dontkillmyapp.com/problem
Hi, I think you did not understood me, the app is not killed me. The awake lock is still running in the background and drain the battery, even i close the app.
The second problem, When i turn off the screen there is lag(delay) in the gps location. See also reference here: https://github.com/ocetnik/react-native-background-timer/issues/13
Please assist, thanks. (By the way, awesome library!)
Hi, I think you did not understood me, the app is not killed me. The awake lock is still running in the background and drain the battery, even i close the app.
The second problem, When i turn off the screen there is lag(delay) in the gps location.
Please assist, thanks. (By the way, awesome library!)
Oh okay I got it! Yes I didn't know that. So it means that if the app is not closed I still have those locks draining the battery... Ok so it's even worse than I expected.
Yes, my users not happy :( Maybe you know how to fix it?
And also about delayed gps when the screen is off ?
@roysG I'm not the developer of this library and I'm not familiar with the codebase. I've just reported a problem that I'm having right now.
oh sorry.
@ocetnik , can you assist?
same issue, no any solution yet?
This solution work for me
For Starting timer must do like this.
startTimer = async () => {
this.setState(() => ({ timerValue: TIMER_INTERVAL }));
if (isAndroid) {
await BackgroundTimer.runBackgroundTimer(() => this.updateValue(), 1000);
} else {
await BackgroundTimer.start();
timer = BackgroundTimer.setInterval(() => {
this.updateValue()
}, 1000);
}
}
For stopping timer must do like this.
resetTimer = async () => {
this.setState({ timerValue: 0, timerDisplayValue: '' });
if (isAndroid) {
await BackgroundTimer.stopBackgroundTimer();
}
if (timer) {
await BackgroundTimer.clearInterval(timer)
}
await BackgroundTimer.stop()
}
i've found some solution, but i'm not sure how much is it correct
modify index.js as 1)
this.uniqueId = 0
this.callbacks = {}
this.bool = true <--------- ADD THIS ONE
backgroundClockMethod(callback, delay) {
this.backgroundTimer = this.setTimeout(() => {
if (this.bool) { <--------- ADD
callback()
this.backgroundClockMethod(callback, delay)
} <--------- ADD
}, delay)
}
stopBackgroundTimer() {
this.bool = false <--------- AND THIS LAST
this.stop()
this.clearTimeout(this.backgroundTimer)
}
and use for IOS and ANDROID
BackgroundTimer.runBackgroundTimer(() => { //CODE HERE }, delay)
BackgroundTimer.stopBackgroundTimer()
@davidcunha try this solution from stackoverflow, worked for me on android and ios https://stackoverflow.com/questions/54833140/react-native-background-timer-never-stops/56473096#56473096
@davidcunha try this solution from stackoverflow, worked for me on android and ios https://stackoverflow.com/questions/54833140/react-native-background-timer-never-stops/56473096#56473096
If i set a timer of 60 seconds and i background the app in ios the app gets terminated after 30 seconds.
It seems like we are experiencing this too now. Are others too?
Does anyone have an idea what is the source of the issue?