1

I have an app that do recursive calls to a API after every min or so it is working fine while app is active but not working when it is in background.

I tested the same app on android and even in the background it work fine, but on iOS it stop calling the API.

Am I missing something or what should I do to resolve it?

Any quick help please?

Aamir Munir
  • 33
  • 1
  • 1
  • 5
  • I was looking for solution and found this link: http://stackoverflow.com/questions/37565643/background-execution-automatically-stops-after-3-minutes it also explain here that it is possible: https://krumelur.me/2015/11/25/ios-background-transfer-what-about-uploads/ but sill not able to resolve it. – Aamir Munir Feb 01 '17 at 19:26
  • did you find the solution for this issue? – Ega Setya Putra Aug 16 '17 at 05:09

2 Answers2

2

As of January 2017, you have a few options, but none are native for iOS right now—it's something they're working on. For Android (although it seems you have this solved) you can use Headless.js.

For iOS you have a few options, depending on your task:

samcorcos
  • 2,330
  • 4
  • 27
  • 40
  • Thank you for reply, and I already tried : react-native-background-timer but here is what I ma really stuck: once I add import and link this component I am using another mask edit component : react-native-masked-text Now when add both I start getting this error: Mask type not supported. this is how I m using it: this.setState( {Phone: event.nativeEvent.text})} /> – Aamir Munir Jan 26 '17 at 15:03
  • I got it worked :react-native-background-timer ws the solution for me. Thank you – Aamir Munir Jan 26 '17 at 16:37
  • ok I tried to use (react-native-background-timer) this but here what happened: it start working fine but it always stop after 2-3 minutes, I am not sure why but I try everything same result. (I am testing on an iPhone, with and without lock with same result.). Any quick help please? – Aamir Munir Jan 27 '17 at 13:54
  • I've made use of react-native-background-fetch library in my app, but it runs the wanted tasks only a few times per day. Is it normal?? – simaAttar Sep 25 '19 at 09:33
  • Does the above three react libraries work when the app is killed and is not in the background ?? – gorp88 Jun 26 '20 at 02:56
2

In January 2018 there are better options (hooray for progress!). This can now be done entirely in JS cross platform in react native using react native queue and react native background task.

Here's a walkthrough for setting this up.

However, there are limitations:

  • The smallest interval of time between task execution is ~15 min.
  • The background task has a timeout limit of 30 seconds.
  • The task schedule is approximate. iOS/Android use battery life, current cpu load, etc to determine if a scheduled task can be executed or if execution should be delayed or even cancelled. It will generally run when you want it to, but don't expect the timing to be exact.
billmalarky
  • 920
  • 2
  • 12
  • 34