Skip to content

Latest commit

 

History

History
87 lines (57 loc) · 2.84 KB

INSTALL-LINK-IOS.md

File metadata and controls

87 lines (57 loc) · 2.84 KB

iOS Installation with react-native link

With yarn

$ yarn add react-native-background-fetch

With npm

$ npm install --save react-native-background-fetch

react-native link

$ react-native link react-native-background-fetch

pod install

$ cd ios
$ pod install

Configure Background Capabilities

  • Select the root of your project. Select Capabilities tab. Enable Background Modes and enable the following mode:

  • Background fetch

  • Background processing (:new: iOS 13+; Only if you intend to use BackgroundFetch.scheduleTask)

Configure Info.plist (:new: iOS 13+)

  1. Open your Info.plist and the key "Permitted background task scheduler identifiers"

  1. Add the required identifier com.transistorsoft.fetch.

  1. If you intend to execute your own custom tasks via BackgroundFetch.scheduleTask, you must add those custom identifiers as well. For example, if you intend to execute a custom taskId: 'com.foo.customtask', you must add the identifier com.foo.customtask to your "Permitted background task scheduler identifiers", as well.
BackgroundFetch.scheduleTask({
  taskId: 'com.foo.customtask',
  delay: 60 * 60 * 1000  //  In one hour (milliseconds)
});

AppDelegate.m (:new: iOS 13+)

The BGTaskScheduler API introduced in iOS 13 requires special setup:

+#import <TSBackgroundFetch/TSBackgroundFetch.h>

@implementation AppDelegate

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  .
  .
  .
+ // [REQUIRED] Register BackgroundFetch
+ [[TSBackgroundFetch sharedInstance] didFinishLaunching];

  return YES;
}

BackgroundFetch AppDelegate extension

⚠️ Deprecated iOS Background Fetch API for devices running < iOS 13.

BackgroundFetch implements an AppDelegate method didPerformFetchWithCompletionHandler. You must manually add this file to the same folder where your AppDelegate.m lives:

  • In the XCode's Project navigator, right click on project's name ➜ Add Files to <...>.
  • node_modules/react-native-background-fetch/ios/RNBackgroundFetch/RNBackgroundFetch+AppDelegate.m.

node_modules/react-native-background-fetch/ios/RNBackgroundFetch/RNBackgroundFetch+AppDelegate.m