React Native Background Execution Management for iOS
yarn add react-native-background-execution-ios
react-native link react-native-background-execution-ios
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-background-execution-ios
➜ios
and addRCTBackgroundExecutionIOS.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRCTBackgroundExecutionIOS.a
to your project'sBuild Phases
➜Link Binary With Libraries
import BackgroundExecutionIOS from 'react-native-background-execution-ios';
const onExpiration = (remainingTime) => console.info(`Background execution time will end in ${remainingTime}s`);
const onError = (err) => console.warn(err);
BackgroundExecutionIOS.beginBackgroundTask(onExpiration, onError);
//...
const remainingTime = await BackgroundExecutionIOS.backgroundTimeRemaining;
console.log(`Remaining background time: ${remainingTime}s`);
//...
BackgroundExecutionIOS.endBackgroundTask();
Property getters return a promise resolved with the property value.
Property | Type | Notes |
---|---|---|
backgroundTimeRemaining |
double |
readonly |
Method | Arguments | Return | Notes |
---|---|---|---|
beginBackgroundTask |
onExpiration: function , onError: function |
void |
|
endBackgroundTask |
void |
automatically called in case of expiration |