Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out lifecycle protocol #9922

Merged
merged 2 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 98 additions & 86 deletions shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,107 +18,55 @@ NS_ASSUME_NONNULL_BEGIN
@protocol FlutterPluginRegistrar;
@protocol FlutterPluginRegistry;

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man GitHub diffing is pretty crappy. But I'm assuming you're just copy pasting stuff around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just moved around.

* 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<FlutterPluginRegistry>* registry);

/**
* Implemented by the iOS part of a Flutter plugin.
*
* Defines a set of optional callback methods and a method to set up the plugin
* and register it to be called by other application components.
*/
@protocol FlutterPlugin <NSObject>
@required
/**
* Registers this plugin using the context information and callback registration
* methods exposed by the given registrar.
*
* The registrar is obtained from a `FlutterPluginRegistry` which keeps track of
* the identity of registered plugins and provides basic support for cross-plugin
* coordination.
*
* The caller of this method, a plugin registrant, is usually autogenerated by
* Flutter tooling based on declared plugin dependencies. The generated registrant
* asks the registry for a registrar for each plugin, and calls this method to
* allow the plugin to initialize itself and register callbacks with application
* objects available through the registrar protocol.
*
* @param registrar A helper providing application context and methods for
* registering callbacks.
*/
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)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`.
#pragma mark -
/***************************************************************************************************
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these long lines do anything special with doxygen or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, they are ignored by doxygen. It's for the benefit of someone scrolling through the file to see breaks between the top level objects.

* Protocol for listener of events from the UIApplication, typically a FlutterPlugin.
*/
+ (void)setPluginRegistrantCallback:(FlutterPluginRegistrantCallback)callback;
@protocol FlutterApplicationLifeCycleDelegate
@optional
/**
* Called if this plugin has been registered to receive `FlutterMethodCall`s.
*
* @param call The method call command object.
* @param result A callback for submitting the result of the call.
*/
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `NO` if this plugin vetoes application launch.
* @return `NO` if this vetoes application launch.
*/
- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `NO` if this plugin vetoes application launch.
* @return `NO` if this vetoes application launch.
*/
- (BOOL)application:(UIApplication*)application
willFinishLaunchingWithOptions:(NSDictionary*)launchOptions;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*/
- (void)applicationDidBecomeActive:(UIApplication*)application;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*/
- (void)applicationWillResignActive:(UIApplication*)application;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*/
- (void)applicationDidEnterBackground:(UIApplication*)application;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*/
- (void)applicationWillEnterForeground:(UIApplication*)application;

/**
Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
Called if this has been registered for `UIApplicationDelegate` callbacks.
*/
- (void)applicationWillTerminate:(UIApplication*)application;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*/
- (void)application:(UIApplication*)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings
Expand All @@ -127,15 +75,15 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>*
ios(8.0, 10.0));

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*/
- (void)application:(UIApplication*)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application
didReceiveRemoteNotification:(NSDictionary*)userInfo
Expand All @@ -160,69 +108,131 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>*
API_AVAILABLE(ios(10));

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application
openURL:(NSURL*)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application
openURL:(NSURL*)url
sourceApplication:(NSString*)sourceApplication
annotation:(id)annotation;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application
performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
completionHandler:(void (^)(BOOL succeeded))completionHandler
API_AVAILABLE(ios(9.0));

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application
handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
completionHandler:(nonnull void (^)(void))completionHandler;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;

/**
* Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
* Called if this has been registered for `UIApplicationDelegate` callbacks.
*
* @return `YES` if this plugin handles the request.
* @return `YES` if this handles the request.
*/
- (BOOL)application:(UIApplication*)application
continueUserActivity:(NSUserActivity*)userActivity
restorationHandler:(void (^)(NSArray*))restorationHandler;
@end

#pragma mark -
/***************************************************************************************************
* 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<FlutterPluginRegistry>* registry);

#pragma mark -
/***************************************************************************************************
* Implemented by the iOS part of a Flutter plugin.
*
* Defines a set of optional callback methods and a method to set up the plugin
* and register it to be called by other application components.
*/
@protocol FlutterPlugin <NSObject, FlutterApplicationLifeCycleDelegate>
@required
/**
* Registers this plugin using the context information and callback registration
* methods exposed by the given registrar.
*
* The registrar is obtained from a `FlutterPluginRegistry` which keeps track of
* the identity of registered plugins and provides basic support for cross-plugin
* coordination.
*
* The caller of this method, a plugin registrant, is usually autogenerated by
* Flutter tooling based on declared plugin dependencies. The generated registrant
* asks the registry for a registrar for each plugin, and calls this method to
* allow the plugin to initialize itself and register callbacks with application
* objects available through the registrar protocol.
*
* @param registrar A helper providing application context and methods for
* registering callbacks.
*/
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)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.
*
* @param call The method call command object.
* @param result A callback for submitting the result of the call.
*/
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
@end

#pragma mark -
/***************************************************************************************************
*Registration context for a single `FlutterPlugin`, providing a one stop shop
*for the plugin to access contextual information and register callbacks for
*various application events.
Expand Down Expand Up @@ -312,7 +322,8 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>*
- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package;
@end

/**
#pragma mark -
/***************************************************************************************************
* A registry of Flutter iOS plugins.
*
* Plugins are identified by unique string keys, typically the name of the
Expand Down Expand Up @@ -357,12 +368,13 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>*
- (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey;
@end

/**
#pragma mark -
/***************************************************************************************************
* Implement this in the `UIAppDelegate` of your app to enable Flutter plugins to register
* themselves to the application life cycle events.
*/
@protocol FlutterAppLifeCycleProvider
- (void)addApplicationLifeCycleDelegate:(NSObject<FlutterPlugin>*)delegate;
- (void)addApplicationLifeCycleDelegate:(NSObject<FlutterApplicationLifeCycleDelegate>*)delegate;
@end

NS_ASSUME_NONNULL_END;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ FLUTTER_EXPORT
*
* `delegate` will only referenced weakly.
*/
- (void)addDelegate:(NSObject<FlutterPlugin>*)delegate;
- (void)addDelegate:(NSObject<FlutterApplicationLifeCycleDelegate>*)delegate;

/**
* Calls all plugins registered for `UIApplicationDelegate` callbacks.
Expand Down
Loading