From 4d95357fcb67272a00edbe3b5b0a77dda9f361e6 Mon Sep 17 00:00:00 2001 From: mlch911 Date: Sat, 7 May 2022 23:03:16 +0800 Subject: [PATCH] Update: BackgroundServicePlugin --- ios/Podfile.lock | 2 +- ios/Runner/AppDelegate.swift | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 5fbfb6c..fb8cb63 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -211,4 +211,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 472b36355d7f1afce121640438e776da12affe90 -COCOAPODS: 1.11.2 +COCOAPODS: 1.11.3 diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 94837bd..f564183 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,18 +1,25 @@ import UIKit import Flutter import flutter_downloader +import flutter_background_service @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - GeneratedPluginRegistrant.register(with: self) - FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins) + AppDelegate.registerPlugins(with: self) + FlutterDownloaderPlugin.setPluginRegistrantCallback { registry in + if (!registry.hasPlugin("FlutterDownloaderPlugin")) { + FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!) + } + } + SwiftFlutterBackgroundServicePlugin.setPluginRegistrantCallback { registry in + AppDelegate.registerPlugins(with: registry) + } + return super.application(application, didFinishLaunchingWithOptions: launchOptions) } -} - -private func registerPlugins(registry: FlutterPluginRegistry) { - if (!registry.hasPlugin("FlutterDownloaderPlugin")) { - FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!) + + static func registerPlugins(with registry: FlutterPluginRegistry) { + GeneratedPluginRegistrant.register(with: registry) } }