Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
react-native-background-task
Advanced tools
WORK IN PROGRESS / NOT YET READY FOR PRODUCTION USE
Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
This builds on top of the native modules provided by the following two libraries:
Background Fetch
technique.To achieve a unified API, this package exposes the lowest common denominator (e.g. only support for a single task, even though Android can support multiple).
For more per-platform flexibility, those libraries should be used individually.
$ npm install --save react-native-background-task
register(task, options)
Define the task that this module should be executing.
console.error
if it can't register the taskParameters:
task
: required () => void
- Function to be executed in the background
options
: ?object
- Any configuration you want to be set with
the task. Note that most of these will only work on one platform.
period
number
- (Android only) Desired number of seconds between each
execution of the task. Even on Android, the OS will only take this as a
recommendation, and will likely enforce a minimum of 15 minutes (similar to
iOS). Default is 900 (15 minutes)timeout
number
- (Android only) Number of seconds the task will have
to execute. iOS has a hardcoded limit of 30 seconds. Default 30 seconds.cancel()
Cancels any currently registered task.
finish()
Must be called at the end of your task to indicate to the OS that it's finished. (Only required on iOS, no-op on Android).
import React from 'react'
import { Text } from 'react-native'
import BackgroundTask from 'react-native-background-task'
BackgroundTask.register(() => {
console.log('Hello from a background task')
BackgroundTask.finish()
})
class MyApp extends React.Component {
render() {
return <Text>Hello world</Text>
}
}
import React from 'react'
import { AsyncStorage, Button, Text } from 'react-native'
import BackgroundTask from 'react-native-background-task'
BackgroundTask.register(async () => {
// Fetch some data over the network which we want the user to have an up-to-
// date copy of, even if they have no network when using the app
const response = await fetch('http://feeds.bbci.co.uk/news/rss.xml')
const text = await response.text()
// Data persisted to AsyncStorage can later be accessed by the foreground app
await AsyncStorage.setItem('@MyApp:key', text)
// Remember to call finish()
BackgroundTask.finish()
}, {
period: 1800, // Aim to run every 30 mins - more conservative on battery
})
class MyApp extends React.Component {
render() {
return (
<View>
<Button
title="Read results from AsyncStorage"
onPress={async () => {
const result = await AsyncStorage.getItem('@MyApp:key')
console.log(result)
}}
/>
</View>
)
}
}
FAQs
Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
The npm package react-native-background-task receives a total of 72 weekly downloads. As such, react-native-background-task popularity was classified as not popular.
We found that react-native-background-task demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.