npm install cordova-plugin-background-fetch
npx cap sync
With YourApp.xcworkspace
open in XCode, add the following Background Modes Capability:
- Background fetch
The Background Geolocation SDK is integrated with the 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 {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
+ //Added for cordova-plugin-background-fetch
+ func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler:@escaping (UIBackgroundFetchResult) -> Void) {
+ NSLog("AppDelegate received fetch event");
+ let fetchManager = TSBackgroundFetch.sharedInstance();
+ fetchManager?.perform(completionHandler: completionHandler, applicationState: application.applicationState);
+ }
.
.
.
}
Nothing else to perform