Background Fetch is a very simple plugin which will awaken an app in the background about every 15 minutes, providing a short period of background running-time. This plugin will execute your provided
callbackFn
whenever a background-fetch event occurs.
import BackgroundFetch from "react-native-background-fetch";
export default class App extends Component {
componentDidMount() {
// Configure it.
BackgroundFetch.configure({
minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
// Android options
forceAlarmManager: false, // <-- Set true to bypass JobScheduler.
stopOnTerminate: false,
startOnBoot: true,
requiredNetworkType: BackgroundFetch.NETWORK_TYPE_NONE, // Default
requiresCharging: false, // Default
requiresDeviceIdle: false, // Default
requiresBatteryNotLow: false, // Default
requiresStorageNotLow: false // Default
}, async (taskId) => {
console.log("[js] Received background-fetch event: ", taskId);
// Required: Signal completion of your task to native code
// If you fail to do this, the OS can terminate your app
// or assign battery-blame for consuming too much background-time
BackgroundFetch.finish(taskId);
}, (error) => {
console.log("[js] RNBackgroundFetch failed to start");
});
}
};
From the source I see that on iOS it leverages the BackgroundTasks framework. Do note that the os might decide to throttle the rate the background-fetch so the define interval is only a minimum.