Skip to content

Latest commit

 

History

History
76 lines (48 loc) · 2.88 KB

INSTALL_CAPACITOR.md

File metadata and controls

76 lines (48 loc) · 2.88 KB

Capacitor Setup


🆕 🛑 Capacitor version now available! See capacitor-background-fetch 🛑


npm install cordova-plugin-background-fetch
npx cap sync

iOS Setup

Configure Background Capabilities

With YourApp.xcworkspace open in XCode, add the following Background Modes Capability:

  • Background fetch
  • Background processing (Only if you intend to use BackgroundFetch.scheduleTask)

Configure Info.plist — 🆕 iOS 13+

  1. Open your Info.plist and add 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.transistorsoft.customtask', you must add the identifier com.transistorsoft.customtask to your "Permitted background task scheduler identifiers", as well.

⚠️ A task identifier can be any string you wish, but it's a good idea to prefix them now with com.transistorsoft. — In the future, the com.transistorsoft prefix may become required.

BackgroundFetch.scheduleTask(TaskConfig(
  taskId: 'com.transistorsoft.customtask',
  delay: 60 * 60 * 1000  //  In one hour (milliseconds)
));

AppDelegate.swift

For devices running iOS < 13, the Background Geolocation SDK will implement the deprecated iOS Background Fetch API.

In Your AppDelegate.swift, add the following code (just the +green lines):

import UIKit
import Capacitor
+import TSBackgroundFetch

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

+ // Added for cordova-plugin-background-fetch
+ func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler:@escaping (UIBackgroundFetchResult) -> Void) {
+   NSLog("AppDelegate received fetch event");
+   TSBackgroundFetch.sharedInstance().perform(completionHandler: completionHandler, applicationState: application.applicationState);
+ }
  .
  .
  .
}

Android Setup

Nothing else to perform