fix: enable background fetch on iOS

This commit is contained in:
Rainer Killinger
2022-02-02 17:27:42 +01:00
parent 1195c5ffc8
commit a1592f84cc
2 changed files with 14 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import UIKit import UIKit
import Capacitor import Capacitor
import TSBackgroundFetch
@UIApplicationMain @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -8,9 +9,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
let fetchManager = TSBackgroundFetch.sharedInstance();
fetchManager?.didFinishLaunching();
return true 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) { 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. // 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. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

View File

@@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.transistorsoft.fetch</string>
</array>
<key>NSCalendarsUsageDescription</key> <key>NSCalendarsUsageDescription</key>
<string>App uses calendar for schedule sync</string> <string>App uses calendar for schedule sync</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>