From a1592f84cc48f7cae8c55ef806cddbe806034bb5 Mon Sep 17 00:00:00 2001 From: Rainer Killinger Date: Wed, 2 Feb 2022 17:27:42 +0100 Subject: [PATCH] fix: enable background fetch on iOS --- ios/App/App/AppDelegate.swift | 10 ++++++++++ ios/App/App/Info.plist | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/ios/App/App/AppDelegate.swift b/ios/App/App/AppDelegate.swift index 53e37603..70d22731 100644 --- a/ios/App/App/AppDelegate.swift +++ b/ios/App/App/AppDelegate.swift @@ -1,5 +1,6 @@ import UIKit import Capacitor +import TSBackgroundFetch @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -8,9 +9,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. + let fetchManager = TSBackgroundFetch.sharedInstance(); + fetchManager?.didFinishLaunching(); return true } + // [capacitor-background-fetch-plugin] + func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { + print("BackgroundFetchPlugin AppDelegate received fetch event"); + let fetchManager = TSBackgroundFetch.sharedInstance(); + fetchManager?.perform(completionHandler: completionHandler, applicationState: application.applicationState); + } + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. diff --git a/ios/App/App/Info.plist b/ios/App/App/Info.plist index fb308c73..e947981e 100644 --- a/ios/App/App/Info.plist +++ b/ios/App/App/Info.plist @@ -2,6 +2,10 @@ + BGTaskSchedulerPermittedIdentifiers + + com.transistorsoft.fetch + NSCalendarsUsageDescription App uses calendar for schedule sync CFBundleDevelopmentRegion