3.5 KiB
3.5 KiB
BackgroundTask
[Call a nanoflow when app is in background]
Features
[feature highlights]
Usage
- Clone this Git
- Go to cloned directory
- Run: npm i
- Run: cd ios && pod install
- Follow steps below:
iOS
Select the root of your project. Select Capabilities tab. Enable Background Modes and enable the following mode:
- Background fetch
Configure Info.plist (iOS 13+)
Open your Info.plist and add the key "Permitted background task scheduler identifiers"

Add the required identifier com.transistorsoft.fetch.
AppDelegate.m (iOS 13+)
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
+//IMPORTANT: Paste import ABOVE the DEBUG macro
+#import <TSBackgroundFetch/TSBackgroundFetch.h>
#if DEBUG
.
. ///////////////////////////////////////////////////////////////////////////////////
. // IMPORTANT: DO NOT paste import within DEBUG macro or archiving will fail!!!
. ///////////////////////////////////////////////////////////////////////////////////
.
#endif
@implementation AppDelegate
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
.
.
.
+//[REQUIRED] Register BackgroundFetch
+[[TSBackgroundFetch sharedInstance] didFinishLaunching];
return YES;
}
Android
android/build.gradle
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
+ maven {
+ // react-native-background-fetch
+ url("${project(':react-native-background-fetch').projectDir}/libs")
+ }
}
}
Configure proguard-rules.pro
If you're using minifyEnabled true with your Android release build, the plugin's HeadlessTask class will be mistakenly removed and you will have this crash.
- Edit
android/app/proguard-rules.pro. - Add the following rule:
# [react-native-background-fetch]
-keep class com.transistorsoft.rnbackgroundfetch.HeadlessTask { *; }
Issues, suggestions and feature requests
https://github.com/IncentroBA/backgroundTask/issues