I have been following the Flutter Workmanager iOS setup and at the bottom of the page they show how to use plug-ins with the Workmanager for background tasks.
I have this exact code in my AppDelegate.swift:
class AppDelegate: FlutterAppDelegate {
/// Registers all pubspec-referenced Flutter plugins in the given registry.
static func registerPlugins(with registry: FlutterPluginRegistry) {
GeneratedPluginRegistrant.register(with: registry)
}
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ... Initialization code
AppDelegate.registerPlugins(with: self) // Register the app's plugins in the context of a normal run
WorkmanagerPlugin.setPluginRegistrantCallback { registry in
// The following code will be called upon WorkmanagerPlugin's registration.
// Note : all of the app's plugins may not be required in this context ;
// instead of using GeneratedPluginRegistrant.register(with: registry),
// you may want to register only specific plugins.
AppDelegate.registerPlugins(with: registry)
}
}
}
Their comment at the end implies that I can register specific plugins, which I want to do instead of loading every plug-in that I have installed.
I have tried to do something within the .setPluginRegistrantCallback brackets like:
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
but this doesn't seem to work since the Workmanager keeps returning with a failed result after I simulate a background fetch in xCode:
[<workmanager.SwiftWorkmanagerPlugin: 0x600003b5b060>] application(_:performFetchWithCompletionHandler:) -> UIBackgroundFetchResult.failed (finished in 0.24 seconds)
If someone could help me register a specific plug-in, like Geolocator or anything else, that would be great. Instead of registering all the plug-ins through the GeneratedPluginRegistrant.