background_locator
background_locator copied to clipboard
[iOS 🐛] Compatibility with other plugin
The issue
I'm developing a plugin which uses a native SDK to operate. The issue is that when adding my plugin and background_locator to an app, the native SDK of my plugin can no longer communicate with my dart code.
After investigating, is seems that the problematic part is the swift code you ask to add during initialization:
BackgroundLocatorPlugin.setPluginRegistrantCallback { registry in
if (!registry.hasPlugin("BackgroundLocatorPlugin")) {
GeneratedPluginRegistrant.register(with: registry)
}
}
The issue is that this code calls registerWithRegistar on my plugin, with the registrar you are giving (which is a FlutterEngine). It appears that channels created with this registrar are broken (I managed to reproduce the issue with thequick_actions plugin as well).
Question 1:
Can you explain the reason why do you recommend adding this code when using the background_locator plugin? Especially since, it seems like any other call to registerWithRegistrar occurring after the 1st one is ignored according to the following code:
+ (void)registerWithRegistrar:(nonnull NSObject<FlutterPluginRegistrar> *)registrar {
@synchronized(self) {
if (instance == nil) { // False during the call to `GeneratedPluginRegistrant.register(with: registry)`since `GeneratedPluginRegistrant.register(with: self)` was already called
instance = [[BackgroundLocatorPlugin alloc] init:registrar];
[registrar addApplicationDelegate:instance];
}
}
}
Question 2:
In the documentation "Use other plugins in callback" you recommend using the following code for other plugins:
if !hasPlugin("io.flutter.plugins.pathprovider") {
FLTPathProviderPlugin
.register(with: registrar(forPlugin: "io.flutter.plugins.pathprovider"))
}
Is there a reason the setup of background_locator and the setup of additional plugin is different ? The first makes us register a second time ALL plugins, while the second only registers background_locator. Should we replace the setup section with the following :
BackgroundLocatorPlugin.setPluginRegistrantCallback { registry in
if (!registry.hasPlugin("BackgroundLocatorPlugin")) {
BackgroundLocatorPlugin.register(with: registry.registrar(forPlugin: "BackgroundLocatorPlugin")!)
}
}
Hi, have you found any answers to your questions ? I feel like I can't really use other plugins too
Hi, unfortunately not. I spent a lot of time digging into this problem and this issue was the last call for help (which went on unanswered as you can see 😉)
Sorry to hear that, thanks for the update :)