From 1ba32955066954f7fb5bbc793a4954b529a4a8c8 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Fri, 15 Feb 2019 11:18:56 -0800 Subject: [PATCH] Add support for calling into other plugins from a background context on iOS (#7843) Added `FlutterPluginRegistrantCallback` typedef and optional `setPluginRegistrantCallback` static method in `FlutterPlugin`. `setPluginRegistrantCallback` is used to set a callback defined in AppDelegate.m which registers some subset of plugins with a `FlutterPluginRegistry` (for example, a headless FlutterEngine). This allows for plugins which utilize background execution functionality to enable the use of other plugins on the background isolate. This puts iOS on par with Android for background execution. Along with updated examples and Medium posts, this fixes [flutter/flutter#21925](https://github.com/flutter/flutter/issues/21925). --- .../ios/framework/Headers/FlutterPlugin.h | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index bc6997f48b2be..4b340bf7b9e78 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -16,6 +16,17 @@ NS_ASSUME_NONNULL_BEGIN @protocol FlutterPluginRegistrar; +@protocol FlutterPluginRegistry; + +/** + * A plugin registration callback. + * + * Used for registering plugins with additional instances of + * `FlutterPluginRegistry`. + * + * @param registry The registry to register plugins with. + */ +typedef void (*FlutterPluginRegistrantCallback)(NSObject* registry); /** * Implemented by the iOS part of a Flutter plugin. @@ -44,6 +55,19 @@ NS_ASSUME_NONNULL_BEGIN */ + (void)registerWithRegistrar:(NSObject*)registrar; @optional +/** + * Set a callback for registering plugins to an additional `FlutterPluginRegistry`, + * including headless `FlutterEngine` instances. + * + * This method is typically called from within an application's `AppDelegate` at + * startup to allow for plugins which create additional `FlutterEngine` instances + * to register the application's plugins. + * + * @param callback A callback for registering some set of plugins with a + * `FlutterPluginRegistry`. + */ ++ (void)setPluginRegistrantCallback:(FlutterPluginRegistrantCallback)callback; +@optional /** * Called if this plugin has been registered to receive `FlutterMethodCall`s. *