background_locator icon indicating copy to clipboard operation
background_locator copied to clipboard

[iOS 🐛] Compatibility with other plugin

Open lulupointu opened this issue 3 years ago • 3 comments

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")!)
    }
}

lulupointu avatar Mar 10 '22 08:03 lulupointu

Hi, have you found any answers to your questions ? I feel like I can't really use other plugins too

Yukams avatar Jul 12 '22 17:07 Yukams

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 😉)

lulupointu avatar Jul 13 '22 07:07 lulupointu

Sorry to hear that, thanks for the update :)

Yukams avatar Jul 13 '22 12:07 Yukams