React Native: Background Task Management in iOS
React Native background tasks can be useful in a number of ways, from aiding in the user experience to managing authentication mechanisms and analytics data. Background tasks are triggered behind the scenes even if the app is not running. What is impressive, and extremely useful, is the ability to tie these tasks into React Native code, giving the developer the ability to do things like contact remote servers through
fetch requests, and update
AsyncStorage values (or other database solutions you may have such as SQLLite or Realm).
Background tasks are also a useful way to tackle syncing issues, by allowing an app to do housekeeping while the app is not running in the foreground. In an ideal world, an app should display the most up to date app state from the moment it is opened. This problem is magnified when apps go multi-platform, whereby users may be using a web or desktop version of a service before jumping back into the native app — expecting those updates to have taken effect.
There are a few packages available for background task management in React Native, and this article will showcase the most reliable of them. These packages support both Android and iOS, but will be demoed around iOS throughout this piece.
Limitations of background tasks
It is important to note that the implementation of background processes differ between iOS and Android, and iOS in-particular comes with strict limitations in terms of background task usage.
For example, iOS invokes a minimum waiting period of 15 minutes before background tasks are triggered, the timing of which is also dependent on battery drain and frequency of app usage. Because of this, it could be hours before the next background task is fired. Because of this inconsistency and unpredictability, background tasks should not be mission critical, and instead should be used to supplement foreground processes. Apple discuss in more detail about how background tasks are executed here.
Integrating Background Tasks
This section documents some of the background task managers that have been…