npm i react-native-background-timer
React Native Background Timer
Emit event periodically (even when app is in the background).
- If you use Expo to create a project you’ll just need to “eject“.
- Install React Native Background Timer package.
yarn add react-native-background-timer# or using npmnpm install react-native-background-timer –save
- Link React Native Background Timer library. This step is not necessary when you use React Native >= 0.60 (and your app is not ejected from Expo).
react-native link react-native-background-timer
- If you use CocoaPods or React Native >= 0.60 (and your app is not ejected from Expo) or your app is ejected from Expo, then before running your app on iOS, make sure you have CocoaPods installed and run:
cd iospod install
Link the library manually if you get errors:
TypeError: Cannot read property 'setTimeout' of undefinedor
TypeError: null is not an object (evaluating 'RNBackgroundTimer.setTimeout')
Native module cannot be null
Android manual linking
iOS manual linking
To use the same code both on Android and iOS use runBackgroundTimer() and stopBackgroundTimer(). There can be used only one background timer to keep code consistent.
You can use the
setTimeout functions. This API is identical to that of
react-native and can be used to quickly replace existing timers with background timers.
Obsolete usage which doesn’t support multiple background timers.