Installations
npm install react-native-background-timer
Score
48.7
Supply Chain
53.7
Quality
68.6
Maintenance
50
Vulnerability
95.6
License
Releases
Unable to fetch releases
Developer
ocetnik
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
10.16.2
NPM Version
6.9.0
Statistics
1,621 Stars
381 Commits
231 Forks
22 Watching
9 Branches
25 Contributors
Updated on 19 Nov 2024
Bundle Size
1.43 kB
Minified
575.00 B
Minified + Gzipped
Languages
Java (37.48%)
Objective-C (30.74%)
JavaScript (25.74%)
Ruby (6.04%)
Total Downloads
Cumulative downloads
Total Downloads
9,066,108
Last day
-16.3%
10,691
Compared to previous day
Last week
2.1%
62,816
Compared to previous week
Last month
4.8%
265,802
Compared to previous month
Last year
21.6%
2,520,827
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
React Native Background Timer
Emit event periodically (even when app is in the background).
Installation
-
If you use Expo to create a project you'll just need to "eject".
1expo eject
-
Install React Native Background Timer package.
1yarn add react-native-background-timer 2# or using npm 3npm 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).
1react-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:
1cd ios 2pod install
Link the library manually if you get errors:
- Android:
TypeError: Cannot read property 'setTimeout' of undefined
orTypeError: null is not an object (evaluating 'RNBackgroundTimer.setTimeout')
- iOS:
Native module cannot be null
Android manual linking
-
android/settings.gradle
1+ include ':react-native-background-timer' 2+ project(':react-native-background-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer/android')
-
android/app/build.gradle
1dependencies { 2+ implementation project(':react-native-background-timer') 3}
-
android/app/src/main/java/com/your-app/MainApplication.java
1+ import com.ocetnik.timer.BackgroundTimerPackage; 2 3@Override 4protected List<ReactPackage> getPackages() { 5 return Arrays.<ReactPackage>asList( 6+ new BackgroundTimerPackage() 7 ); 8}
iOS manual linking
-
ios/Podfile
1+ pod 'react-native-background-timer', :path => '../node_modules/react-native-background-timer'
Usage
1import BackgroundTimer from 'react-native-background-timer';
Crossplatform
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.
1BackgroundTimer.runBackgroundTimer(() => {
2//code that will be called every 3 seconds
3},
43000);
5//rest of code will be performing for iOS on background too
6
7BackgroundTimer.stopBackgroundTimer(); //after this call all code on background stop run.
iOS
After iOS update logic of background task little bit changed. So we can't use as it was. You have to use only start() and stop() without parameters. And all code that is performing will continue performing on background including all setTimeout() timers.
Example:
1BackgroundTimer.start();
2// Do whatever you want incuding setTimeout;
3BackgroundTimer.stop();
If you call stop() on background no new tasks will be started! Don't call .start() twice, as it stop performing previous background task and starts new. If it will be called on backgound no tasks will run.
Android
You can use the setInterval
and setTimeout
functions.
This API is identical to that of react-native
and can be used to quickly replace existing timers
with background timers.
1// Start a timer that runs continuous after X milliseconds
2const intervalId = BackgroundTimer.setInterval(() => {
3 // this will be executed every 200 ms
4 // even when app is the the background
5 console.log('tic');
6}, 200);
7
8// Cancel the timer when you are done with it
9BackgroundTimer.clearInterval(intervalId);
1// Start a timer that runs once after X milliseconds
2const timeoutId = BackgroundTimer.setTimeout(() => {
3 // this will be executed once after 10 seconds
4 // even when app is the the background
5 console.log('tac');
6}, 10000);
7
8// Cancel the timeout if necessary
9BackgroundTimer.clearTimeout(timeoutId);
Obsolete
Obsolete usage which doesn't support multiple background timers.
1import { 2 DeviceEventEmitter, 3 NativeAppEventEmitter, 4 Platform, 5} from 'react-native'; 6 7import BackgroundTimer from 'react-native-background-timer';
1const EventEmitter = Platform.select({ 2 ios: () => NativeAppEventEmitter, 3 android: () => DeviceEventEmitter, 4})();
1// start a global timer 2BackgroundTimer.start(5000); // delay in milliseconds only for Android
1// listen for event 2EventEmitter.addListener('backgroundTimer', () => { 3 // this will be executed once after 5 seconds 4 console.log('toe'); 5});
1// stop the timer
2BackgroundTimer.stop();
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
17 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-rxrc-rgv4-jpvx
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
Score
2.4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-native-background-timer
@types/react-native-background-timer
TypeScript definitions for react-native-background-timer
react-native-background-timer-android
setInterval and setTimeout that work even if the app is running in the background
react-idle-timer
Activity detection for React.js
react-native-countdown-circle-timer
Lightweight React Native countdown timer component with color and progress animation based on SVG