Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
FlutterPlugin.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_HEADERS_FLUTTERPLUGIN_H_
6#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_HEADERS_FLUTTERPLUGIN_H_
7
8#import <UIKit/UIKit.h>
9#import <UserNotifications/UNUserNotificationCenter.h>
10
12#import "FlutterChannels.h"
13#import "FlutterCodecs.h"
16#import "FlutterTexture.h"
17
19@protocol FlutterPluginRegistrar;
20@protocol FlutterPluginRegistry;
21
22#pragma mark -
23/**
24 * Protocol for listener of events from the UIApplication, typically a FlutterPlugin.
25 */
26@protocol FlutterApplicationLifeCycleDelegate <UNUserNotificationCenterDelegate>
27
28@optional
29/**
30 * Called if this has been registered for `UIApplicationDelegate` callbacks.
31 *
32 * @return `NO` if this vetos application launch.
33 */
34- (BOOL)application:(UIApplication*)application
35 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions;
36
37/**
38 * Called if this has been registered for `UIApplicationDelegate` callbacks.
39 *
40 * @return `NO` if this vetos application launch.
41 */
42- (BOOL)application:(UIApplication*)application
43 willFinishLaunchingWithOptions:(NSDictionary*)launchOptions;
44
45/**
46 * Called if this has been registered for `UIApplicationDelegate` callbacks.
47 */
48- (void)applicationDidBecomeActive:(UIApplication*)application;
49
50/**
51 * Called if this has been registered for `UIApplicationDelegate` callbacks.
52 */
53- (void)applicationWillResignActive:(UIApplication*)application;
54
55/**
56 * Called if this has been registered for `UIApplicationDelegate` callbacks.
57 */
58- (void)applicationDidEnterBackground:(UIApplication*)application;
59
60/**
61 * Called if this has been registered for `UIApplicationDelegate` callbacks.
62 */
63- (void)applicationWillEnterForeground:(UIApplication*)application;
64
65/**
66 Called if this has been registered for `UIApplicationDelegate` callbacks.
67 */
68- (void)applicationWillTerminate:(UIApplication*)application;
69
70/**
71 * Called if this has been registered for `UIApplicationDelegate` callbacks.
72 */
73- (void)application:(UIApplication*)application
74 didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings
75 API_DEPRECATED(
76 "See -[UIApplicationDelegate application:didRegisterUserNotificationSettings:] deprecation",
77 ios(8.0, 10.0));
78
79/**
80 * Called if this has been registered for `UIApplicationDelegate` callbacks.
81 */
82- (void)application:(UIApplication*)application
83 didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;
84
85/**
86 * Called if this has been registered for `UIApplicationDelegate` callbacks.
87 */
88- (void)application:(UIApplication*)application
89 didFailToRegisterForRemoteNotificationsWithError:(NSError*)error;
90
91/**
92 * Called if this has been registered for `UIApplicationDelegate` callbacks.
93 *
94 * @return `YES` if this handles the request.
95 */
96- (BOOL)application:(UIApplication*)application
97 didReceiveRemoteNotification:(NSDictionary*)userInfo
98 fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;
99
100/**
101 * Calls all plugins registered for `UIApplicationDelegate` callbacks.
102 */
103- (void)application:(UIApplication*)application
104 didReceiveLocalNotification:(UILocalNotification*)notification
105 API_DEPRECATED(
106 "See -[UIApplicationDelegate application:didReceiveLocalNotification:] deprecation",
107 ios(4.0, 10.0));
108
109/**
110 * Called if this has been registered for `UIApplicationDelegate` callbacks.
111 *
112 * @return `YES` if this handles the request.
113 */
114- (BOOL)application:(UIApplication*)application
115 openURL:(NSURL*)url
116 options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options;
117
118/**
119 * Called if this has been registered for `UIApplicationDelegate` callbacks.
120 *
121 * @return `YES` if this handles the request.
122 */
123- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url;
124
125/**
126 * Called if this has been registered for `UIApplicationDelegate` callbacks.
127 *
128 * @return `YES` if this handles the request.
129 */
130- (BOOL)application:(UIApplication*)application
131 openURL:(NSURL*)url
132 sourceApplication:(NSString*)sourceApplication
133 annotation:(id)annotation;
134
135/**
136 * Called if this has been registered for `UIApplicationDelegate` callbacks.
137 *
138 * @return `YES` if this handles the request.
139 */
140- (BOOL)application:(UIApplication*)application
141 performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
142 completionHandler:(void (^)(BOOL succeeded))completionHandler
143 API_AVAILABLE(ios(9.0));
144
145/**
146 * Called if this has been registered for `UIApplicationDelegate` callbacks.
147 *
148 * @return `YES` if this handles the request.
149 */
150- (BOOL)application:(UIApplication*)application
151 handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
152 completionHandler:(nonnull void (^)(void))completionHandler;
153
154/**
155 * Called if this has been registered for `UIApplicationDelegate` callbacks.
156 *
157 * @return `YES` if this handles the request.
158 */
159- (BOOL)application:(UIApplication*)application
160 performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;
161
162/**
163 * Called if this has been registered for `UIApplicationDelegate` callbacks.
164 *
165 * @return `YES` if this handles the request.
166 */
167- (BOOL)application:(UIApplication*)application
168 continueUserActivity:(NSUserActivity*)userActivity
169 restorationHandler:(void (^)(NSArray*))restorationHandler;
170@end
171
172#pragma mark -
173/**
174 * A plugin registration callback.
175 *
176 * Used for registering plugins with additional instances of
177 * `FlutterPluginRegistry`.
178 *
179 * @param registry The registry to register plugins with.
180 */
181typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>* registry);
182
183#pragma mark -
184/**
185 * Implemented by the iOS part of a Flutter plugin.
186 *
187 * Defines a set of optional callback methods and a method to set up the plugin
188 * and register it to be called by other application components.
189 */
190@protocol FlutterPlugin <NSObject, FlutterApplicationLifeCycleDelegate>
191@required
192/**
193 * Registers this plugin using the context information and callback registration
194 * methods exposed by the given registrar.
195 *
196 * The registrar is obtained from a `FlutterPluginRegistry` which keeps track of
197 * the identity of registered plugins and provides basic support for cross-plugin
198 * coordination.
199 *
200 * The caller of this method, a plugin registrant, is usually autogenerated by
201 * Flutter tooling based on declared plugin dependencies. The generated registrant
202 * asks the registry for a registrar for each plugin, and calls this method to
203 * allow the plugin to initialize itself and register callbacks with application
204 * objects available through the registrar protocol.
205 *
206 * @param registrar A helper providing application context and methods for
207 * registering callbacks.
208 */
209+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;
210@optional
211/**
212 * Set a callback for registering plugins to an additional `FlutterPluginRegistry`,
213 * including headless `FlutterEngine` instances.
214 *
215 * This method is typically called from within an application's `AppDelegate` at
216 * startup to allow for plugins which create additional `FlutterEngine` instances
217 * to register the application's plugins.
218 *
219 * @param callback A callback for registering some set of plugins with a
220 * `FlutterPluginRegistry`.
221 */
222+ (void)setPluginRegistrantCallback:(FlutterPluginRegistrantCallback)callback;
223@optional
224/**
225 * Called if this plugin has been registered to receive `FlutterMethodCall`s.
226 *
227 * @param call The method call command object.
228 * @param result A callback for submitting the result of the call.
229 */
230- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
231@optional
232/**
233 * Called when a plugin is being removed from a `FlutterEngine`, which is
234 * usually the result of the `FlutterEngine` being deallocated. This method
235 * provides the opportunity to do necessary cleanup.
236 *
237 * You will only receive this method if you registered your plugin instance with
238 * the `FlutterEngine` via `-[FlutterPluginRegistry publish:]`.
239 *
240 * @param registrar The registrar that was used to publish the plugin.
241 *
242 */
243- (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;
244@end
245
246#pragma mark -
247/**
248 * How the UIGestureRecognizers of a platform view are blocked.
249 *
250 * UIGestureRecognizers of platform views can be blocked based on decisions made by the
251 * Flutter Framework (e.g. When an interact-able widget is covering the platform view).
252 */
253typedef enum {
254 // NOLINTBEGIN(readability-identifier-naming)
255 /**
256 * Flutter blocks all the UIGestureRecognizers on the platform view as soon as it
257 * decides they should be blocked.
258 *
259 * This policy employs a dual blocking strategy: synchronous blocking via hitTest results and
260 * asynchronous blocking managed through the framework’s gesture arena. With this policy, only the
261 * `touchesBegan` method for all the UIGestureRecognizers is guaranteed to be called.
262 */
264 /**
265 * Flutter blocks all the UIGestureRecognizers on the platform view only after touchesEnded was
266 * invoked.
267 *
268 * This results in the platform view's UIGestureRecognizers seeing the entire touch sequence,
269 * but never recognizing the gesture (and never invoking actions).
270 */
272 /**
273 * Flutter blocks all the UIGestureRecognizers on the platform view based on results from hitTest.
274 *
275 * Unlike FlutterPlatformViewGestureRecognizersBlockingPolicyEager, this policy does not rely on
276 * Flutter's gesture arena. This is a workaround to address a few bugs related to platform view's
277 * gesture recognizers being stuck in a stale state. See:
278 * https://github.com/flutter/flutter/issues/175099.
279 */
281 // NOLINTEND(readability-identifier-naming)
283
284#pragma mark -
285/**
286 * The base interface for `FlutterPluginRegistrar` and `FlutterApplicationRegistrar`.
287 *
288 * Provides registration context for the application or plugins.
289 */
290@protocol FlutterBaseRegistrar <NSObject>
291/**
292 * Returns a `FlutterBinaryMessenger` for creating Dart/iOS communication
293 * channels to be used by the application or a plugin.
294 *
295 * @return The messenger.
296 */
297- (NSObject<FlutterBinaryMessenger>*)messenger;
298
299/**
300 * Returns a `FlutterTextureRegistry` for registering textures
301 * provided by the application or a plugin.
302 *
303 * @return The texture registry.
304 */
305- (NSObject<FlutterTextureRegistry>*)textures;
306
307/**
308 * Registers a `FlutterPlatformViewFactory` for creation of platform views.
309 *
310 * Applications or plugins can expose `UIView` for embedding in Flutter apps by registering a view
311 * factory.
312 *
313 * @param factory The view factory that will be registered.
314 * @param factoryId A unique identifier for the factory, the Dart code of the Flutter app can use
315 * this identifier to request creation of a `UIView` by the registered factory.
316 */
317- (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
318 withId:(NSString*)factoryId;
319
320/**
321 * Registers a `FlutterPlatformViewFactory` for creation of platform views.
322 *
323 * Applications or plugins can expose a `UIView` for embedding in Flutter apps by registering a view
324 * factory.
325 *
326 * @param factory The view factory that will be registered.
327 * @param factoryId A unique identifier for the factory, the Dart code of the Flutter app can use
328 * this identifier to request creation of a `UIView` by the registered factory.
329 * @param gestureRecognizersBlockingPolicy How UIGestureRecognizers on the platform views are
330 * blocked.
331 *
332 */
333- (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
334 withId:(NSString*)factoryId
335 gestureRecognizersBlockingPolicy:
336 (FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizersBlockingPolicy;
337@end
338
339/**
340 * A registrar for Flutter applications.
341 *
342 * This registrar provides access to application-level services, such as the binary messenger and
343 * texture registry.
344 *
345 * See also `FlutterBaseRegistrar`.
346 */
347@protocol FlutterApplicationRegistrar <FlutterBaseRegistrar>
348@end
349
350/**
351 * Registration context for a single `FlutterPlugin`, providing a one stop shop
352 * for the plugin to access contextual information and register callbacks for
353 * various application events.
354 *
355 * Registrars are obtained from a `FlutterPluginRegistry` which keeps track of
356 * the identity of registered plugins and provides basic support for cross-plugin
357 * coordination.
358 */
359@protocol FlutterPluginRegistrar <FlutterBaseRegistrar>
360
361/**
362 * The `UIViewController` whose view is displaying Flutter content.
363 *
364 * The plugin typically should not store a strong reference to this view
365 * controller.
366 *
367 * This property is provided for backwards compatibility for apps that assume
368 * a single view, and will eventually be replaced by the multi-view API variant.
369 *
370 * This property may be |nil|, for instance in a headless environment, or when
371 * the underlying Flutter engine is deallocated.
372 */
373@property(nullable, readonly) UIViewController* viewController;
374
375/**
376 * Publishes a value for external use of the plugin.
377 *
378 * Plugins may publish a single value, such as an instance of the
379 * plugin's main class, for situations where external control or
380 * interaction is needed.
381 *
382 * The published value will be available from the `FlutterPluginRegistry`.
383 * Repeated calls overwrite any previous publication.
384 *
385 * @param value The value to be published.
386 */
387- (void)publish:(NSObject*)value;
388
389/**
390 * Registers the plugin as a receiver of incoming method calls from the Dart side
391 * on the specified `FlutterMethodChannel`.
392 *
393 * @param delegate The receiving object, such as the plugin's main class.
394 * @param channel The channel
395 */
396- (void)addMethodCallDelegate:(NSObject<FlutterPlugin>*)delegate
397 channel:(FlutterMethodChannel*)channel;
398
399/**
400 * Registers the plugin as a receiver of `UIApplicationDelegate` calls.
401 *
402 * @param delegate The receiving object, such as the plugin's main class.
403 */
404- (void)addApplicationDelegate:(NSObject<FlutterPlugin>*)delegate
405 NS_EXTENSION_UNAVAILABLE_IOS("Disallowed in plugins used in app extensions");
406
407/**
408 * Registers the plugin as a receiver of `UISceneDelegate` and `UIWindowSceneDelegate` calls.
409 *
410 * @param delegate The receiving object, such as the plugin's main class.
411 */
412- (void)addSceneDelegate:(NSObject<FlutterSceneLifeCycleDelegate>*)delegate
413 API_AVAILABLE(ios(13.0));
414
415/**
416 * Returns the file name for the given asset.
417 * The returned file name can be used to access the asset in the application's main bundle.
418 *
419 * @param asset The name of the asset. The name can be hierarchical.
420 * @return the file name to be used for lookup in the main bundle.
421 */
422- (NSString*)lookupKeyForAsset:(NSString*)asset;
423
424/**
425 * Returns the file name for the given asset which originates from the specified package.
426 * The returned file name can be used to access the asset in the application's main bundle.
427 *
428 *
429 * @param asset The name of the asset. The name can be hierarchical.
430 * @param package The name of the package from which the asset originates.
431 * @return the file name to be used for lookup in the main bundle.
432 */
433- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package;
434
435/**
436 * Returns a value published by the specified plugin.
437 *
438 * @param pluginKey The unique key identifying the plugin.
439 * @return An object published by the plugin, if any. Will be `NSNull` if
440 * nothing has been published. Will be `nil` if the plugin has not been
441 * registered.
442 */
443- (nullable NSObject*)valuePublishedByPlugin:(NSString*)pluginKey;
444@end
445
446#pragma mark -
447/**
448 * A registry of Flutter iOS plugins.
449 *
450 * Plugins are identified by unique string keys, typically the name of the
451 * plugin's main class. The registry tracks plugins by this key, mapping it to
452 * a value published by the plugin during registration, if any. This provides a
453 * very basic means of cross-plugin coordination with loose coupling between
454 * unrelated plugins.
455 *
456 * Plugins typically need contextual information and the ability to register
457 * callbacks for various application events. To keep the API of the registry
458 * focused, these facilities are not provided directly by the registry, but by
459 * a `FlutterPluginRegistrar`, created by the registry in exchange for the unique
460 * key of the plugin.
461 *
462 * There is no implied connection between the registry and the registrar.
463 * Specifically, callbacks registered by the plugin via the registrar may be
464 * relayed directly to the underlying iOS application objects.
465 */
466@protocol FlutterPluginRegistry <NSObject>
467/**
468 * Returns a registrar for registering a plugin.
469 *
470 * @param pluginKey The unique key identifying the plugin.
471 */
472- (nullable NSObject<FlutterPluginRegistrar>*)registrarForPlugin:(NSString*)pluginKey;
473/**
474 * Returns whether the specified plugin has been registered.
475 *
476 * @param pluginKey The unique key identifying the plugin.
477 * @return `YES` if `registrarForPlugin` has been called with `pluginKey`.
478 */
479- (BOOL)hasPlugin:(NSString*)pluginKey;
480
481/**
482 * Returns a value published by the specified plugin.
483 *
484 * @param pluginKey The unique key identifying the plugin.
485 * @return An object published by the plugin, if any. Will be `NSNull` if
486 * nothing has been published. Will be `nil` if the plugin has not been
487 * registered.
488 */
489- (nullable NSObject*)valuePublishedByPlugin:(NSString*)pluginKey;
490@end
491
492#pragma mark -
493/**
494 * The target of registration of plugins.
495 *
496 * This often is hooked up to the GeneratedPluginRegistrant which is
497 * automatically generated by Flutter for the dependencies listed in the
498 * project.
499 */
500@protocol FlutterPluginRegistrant <NSObject>
501@required
502/**
503 * Register all the plugins for the registrant.
504 *
505 * This will be called after a FlutterEngine has been instantiated, the registry
506 * will connect any plugins to that engine.
507 *
508 * @param registry The registry where plugins will be registered.
509 */
510- (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
511@end
512
513#pragma mark -
514/**
515 * Implement this in the `UIAppDelegate` of your app to enable Flutter plugins to register
516 * themselves to the application life cycle events.
517 *
518 * For plugins to receive events from `UNUserNotificationCenter`, register this as the
519 * `UNUserNotificationCenterDelegate`.
520 */
521@protocol FlutterAppLifeCycleProvider <UNUserNotificationCenterDelegate>
522
523/**
524 * Called when registering a new `FlutterApplicaitonLifeCycleDelegate`.
525 *
526 * See also: `-[FlutterAppDelegate addApplicationLifeCycleDelegate:]`
527 */
528- (void)addApplicationLifeCycleDelegate:(NSObject<FlutterApplicationLifeCycleDelegate>*)delegate;
529@end
530
532
533#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_HEADERS_FLUTTERPLUGIN_H_
void(^ FlutterResult)(id _Nullable result)
#define NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_END
void(* FlutterPluginRegistrantCallback)(NSObject< FlutterPluginRegistry > *registry)
FlutterPlatformViewGestureRecognizersBlockingPolicy
@ FlutterPlatformViewGestureRecognizersBlockingPolicyEager
@ FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded
@ FlutterPlatformViewGestureRecognizersBlockingPolicyDoNotBlockGesture
HWND(* FlutterPlatformViewFactory)(const FlutterPlatformViewCreationParameters *)
FlutterViewController * viewController
int BOOL