Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background timer working on Android, but not iOS #54

Closed
DigohD opened this issue Aug 10, 2017 · 22 comments
Closed

Background timer working on Android, but not iOS #54

DigohD opened this issue Aug 10, 2017 · 22 comments

Comments

@DigohD
Copy link

DigohD commented Aug 10, 2017

When running the same app on Android and iOS, it works perfectly on Android, but on iOS the timer pauses when either pressing the home button or the sleep button. What might I be doing wrong?

@cinder92
Copy link

did you solve this issue?

@DigohD
Copy link
Author

DigohD commented Aug 11, 2017

No I'm still clueless. It simply does not work.

@Metroninja
Copy link

I'm having iOS issues as well, the Background time fires without issue on the Simulator but on a device (iphone 7s ios 10.3) the BackgroundTimer.setInterval will fire ~5% of the time. In testing I have said interval set to 10 seconds (10000ms) but on the rare occasion when the interval does fire, it kicks off a fetch method who's promise never returns/resolves until I open the app back up. Again everything works without issue in the iOS simulator.

Not sure what to do here, I'm currently only starting up the BackgroundTask by monitoring the RN AppState, once it's in the background I kick off the BackgroundTimer. I'm on RN 0.47.1 and using this library 1.2.0

@DigohD
Copy link
Author

DigohD commented Aug 15, 2017

I can't recall my timer firing even once in background mode (iPhone 6s). There are apparently some restrictions when it comes to Apple and background code execution that I've heard from people on stack overflow, but if your timer fires 5% of the time it sounds even weirder.

I've given up on the timers for now and will try to use local notifications instead in order to pass information to the user while not having the app open.

@Metroninja
Copy link

@DigohD - that's actually what I'm attempting to do here, is use local notifications. As soon as the app moves to the background almost all code stops executing after a few seconds making it incredibly difficult to fire local notifications on a given event since the code more or less is dead on an iOS device. The only way I can see this working is with remote notifications if the BackgroundTimer doesn't work.

@martijnplaat
Copy link

martijnplaat commented Aug 15, 2017

I have the same problems. On Android a background process still runs when I minimize the app, but when I minimize the same app on iOS the background process stops working. When I return back to the app the process continues..

Also using RN 0.47.1 and using this library v1.2.0

@perfecten
Copy link

I have the same problems on iPhone devices.

but it is ok on the Simulator.

RN 0.45
this library v1.2.0

@Metroninja
Copy link

Metroninja commented Aug 24, 2017

So this library is probably never going to work unless they implement a feature similar to react-native-background-geolocation. For now I'm using this library on Android, and for iOS I'm running the BackgroundGeolocation with an undocumented watcher BackgroundGeolocation.on('heartbeat', this.heartbeat.bind(this)); and in the config

        preventSuspend: true,
        heartbeatInterval: 15,

so every 15 seconds I'm doing my background tasks.

@y2k-shubham
Copy link

I'm afraid I'm facing even more grave issue: timers won't fire in iOS at all, even when the app is in the foreground.

I've just created a sample app (react-native init) and put BackgroundTimer.setInterval() inside componentDidMount(), which works perfectly fine on Android (even in background unless app is killed from recent apps)
But no timers are fired whatsoever in iOS even when the app is up and running.

react-native v0.47.2
react-native-background-timer v1.2.0
simulator iPhone 6 - iOS 10.3 (14E8301)

@martijnplaat
Copy link

thanks

@orisystech
Copy link

I have the same problem since I upgrade react native to 0.47.2 and this plugin to 1.2.0. the timer work if app is in foreground but not in background.

@Jlexyc
Copy link
Contributor

Jlexyc commented Sep 1, 2017

It worked before for me... but i've got this bug in regression from QAs... Background timer keep working when app in forground but stops when in background.

Strange. Going to check.

@Metroninja
Copy link

More or less this library won't really ever work again - basically it's going to be less and less reliable as versions of android/ios continue to grow. Explained very well below

transistorsoft/react-native-background-geolocation#311 (comment)

@martijnplaat
Copy link

Currently I use react-native-background-geolocation heartbeat for iOS and react-native-background-timer for Android to send the GPS coordinates to a remote server in background mode.

However, reading the comments here (and on transistorsoft/react-native-background-geolocation#311 (comment)) I have the feeling my current implementation is not really future proof.

Am I correct? What is a future proof solution with React Native to automatically send GPS coordinates in background mode? Could I better invest in a solution using Native Modules?

@willbattel
Copy link

Yeah, this is going to be a problem...

@christocracy
Copy link

@ParthBarot-BoTreeConsulting

I believe Apple does not support running infinite/long tasks in background mode, even this lib does not work as when the app goes in background mode the iOS seems to stop the background thread.

@christocracy
Copy link

@ParthBarot-BoTreeConsulting Precisely. This has been known for years in iOS. Once-upon-a-time, Apple allowed these tasks to last 10 minutes. They've shrunk it down to exactly 180 seconds since iOS 6 or 7 due to app developers abusing this mechanism, killing their customers' device battery.

@Jlexyc
Copy link
Contributor

Jlexyc commented Nov 14, 2017

Fix with workaround added. Timer will work while iOS allows to run background task.

@christocracy
Copy link

christocracy commented Nov 14, 2017

180 seconds max in background. That's all iOS will allow a UIBackgroundTaskIdentifier to live before forcefully executing your expirationHandler.

@christocracy
Copy link

christocracy commented Nov 15, 2017

Correction: iOS 11.1 now seems to have decreased the background-time to ~40 seconds.

@ocetnik
Copy link
Owner

ocetnik commented Nov 15, 2017

@Jlexyc #66 merged and v2.0.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests