Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FlutterPlugin.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. #ifndef FLUTTER_FLUTTERPLUGIN_H_
  5. #define FLUTTER_FLUTTERPLUGIN_H_
  6. #import <UIKit/UIKit.h>
  7. #import <UserNotifications/UNUserNotificationCenter.h>
  8. #include "FlutterBinaryMessenger.h"
  9. #include "FlutterChannels.h"
  10. #include "FlutterCodecs.h"
  11. #include "FlutterPlatformViews.h"
  12. #include "FlutterTexture.h"
  13. NS_ASSUME_NONNULL_BEGIN
  14. @protocol FlutterPluginRegistrar;
  15. @protocol FlutterPluginRegistry;
  16. /**
  17. * A plugin registration callback.
  18. *
  19. * Used for registering plugins with additional instances of
  20. * `FlutterPluginRegistry`.
  21. *
  22. * @param registry The registry to register plugins with.
  23. */
  24. typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>* registry);
  25. /**
  26. * Implemented by the iOS part of a Flutter plugin.
  27. *
  28. * Defines a set of optional callback methods and a method to set up the plugin
  29. * and register it to be called by other application components.
  30. */
  31. @protocol FlutterPlugin <NSObject>
  32. @required
  33. /**
  34. * Registers this plugin using the context information and callback registration
  35. * methods exposed by the given registrar.
  36. *
  37. * The registrar is obtained from a `FlutterPluginRegistry` which keeps track of
  38. * the identity of registered plugins and provides basic support for cross-plugin
  39. * coordination.
  40. *
  41. * The caller of this method, a plugin registrant, is usually autogenerated by
  42. * Flutter tooling based on declared plugin dependencies. The generated registrant
  43. * asks the registry for a registrar for each plugin, and calls this method to
  44. * allow the plugin to initialize itself and register callbacks with application
  45. * objects available through the registrar protocol.
  46. *
  47. * @param registrar A helper providing application context and methods for
  48. * registering callbacks.
  49. */
  50. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;
  51. @optional
  52. /**
  53. * Set a callback for registering plugins to an additional `FlutterPluginRegistry`,
  54. * including headless `FlutterEngine` instances.
  55. *
  56. * This method is typically called from within an application's `AppDelegate` at
  57. * startup to allow for plugins which create additional `FlutterEngine` instances
  58. * to register the application's plugins.
  59. *
  60. * @param callback A callback for registering some set of plugins with a
  61. * `FlutterPluginRegistry`.
  62. */
  63. + (void)setPluginRegistrantCallback:(FlutterPluginRegistrantCallback)callback;
  64. @optional
  65. /**
  66. * Called if this plugin has been registered to receive `FlutterMethodCall`s.
  67. *
  68. * @param call The method call command object.
  69. * @param result A callback for submitting the result of the call.
  70. */
  71. - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
  72. /**
  73. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  74. *
  75. * @return `NO` if this plugin vetoes application launch.
  76. */
  77. - (BOOL)application:(UIApplication*)application
  78. didFinishLaunchingWithOptions:(NSDictionary*)launchOptions;
  79. /**
  80. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  81. *
  82. * @return `NO` if this plugin vetoes application launch.
  83. */
  84. - (BOOL)application:(UIApplication*)application
  85. willFinishLaunchingWithOptions:(NSDictionary*)launchOptions;
  86. /**
  87. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  88. */
  89. - (void)applicationDidBecomeActive:(UIApplication*)application;
  90. /**
  91. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  92. */
  93. - (void)applicationWillResignActive:(UIApplication*)application;
  94. /**
  95. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  96. */
  97. - (void)applicationDidEnterBackground:(UIApplication*)application;
  98. /**
  99. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  100. */
  101. - (void)applicationWillEnterForeground:(UIApplication*)application;
  102. /**
  103. Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  104. */
  105. - (void)applicationWillTerminate:(UIApplication*)application;
  106. /**
  107. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  108. */
  109. #pragma GCC diagnostic push
  110. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  111. - (void)application:(UIApplication*)application
  112. didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings;
  113. #pragma GCC diagnostic pop
  114. /**
  115. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  116. */
  117. - (void)application:(UIApplication*)application
  118. didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;
  119. /**
  120. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  121. *
  122. * @return `YES` if this plugin handles the request.
  123. */
  124. - (BOOL)application:(UIApplication*)application
  125. didReceiveRemoteNotification:(NSDictionary*)userInfo
  126. fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;
  127. /**
  128. * Calls all plugins registered for `UIApplicationDelegate` callbacks.
  129. */
  130. - (void)application:(UIApplication*)application
  131. didReceiveLocalNotification:(UILocalNotification*)notification;
  132. /**
  133. * Calls all plugins registered for `UNUserNotificationCenterDelegate` callbacks.
  134. */
  135. - (void)userNotificationCenter:(UNUserNotificationCenter*)center
  136. willPresentNotification:(UNNotification*)notification
  137. withCompletionHandler:
  138. (void (^)(UNNotificationPresentationOptions options))completionHandler
  139. API_AVAILABLE(ios(10));
  140. /**
  141. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  142. *
  143. * @return `YES` if this plugin handles the request.
  144. */
  145. - (BOOL)application:(UIApplication*)application
  146. openURL:(NSURL*)url
  147. options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options;
  148. /**
  149. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  150. *
  151. * @return `YES` if this plugin handles the request.
  152. */
  153. - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url;
  154. /**
  155. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  156. *
  157. * @return `YES` if this plugin handles the request.
  158. */
  159. - (BOOL)application:(UIApplication*)application
  160. openURL:(NSURL*)url
  161. sourceApplication:(NSString*)sourceApplication
  162. annotation:(id)annotation;
  163. /**
  164. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  165. *
  166. * @return `YES` if this plugin handles the request.
  167. */
  168. - (BOOL)application:(UIApplication*)application
  169. performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
  170. completionHandler:(void (^)(BOOL succeeded))completionHandler
  171. API_AVAILABLE(ios(9.0));
  172. /**
  173. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  174. *
  175. * @return `YES` if this plugin handles the request.
  176. */
  177. - (BOOL)application:(UIApplication*)application
  178. handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
  179. completionHandler:(nonnull void (^)(void))completionHandler;
  180. /**
  181. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  182. *
  183. * @return `YES` if this plugin handles the request.
  184. */
  185. - (BOOL)application:(UIApplication*)application
  186. performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;
  187. /**
  188. * Called if this plugin has been registered for `UIApplicationDelegate` callbacks.
  189. *
  190. * @return `YES` if this plugin handles the request.
  191. */
  192. - (BOOL)application:(UIApplication*)application
  193. continueUserActivity:(NSUserActivity*)userActivity
  194. restorationHandler:(void (^)(NSArray*))restorationHandler;
  195. @end
  196. /**
  197. *Registration context for a single `FlutterPlugin`, providing a one stop shop
  198. *for the plugin to access contextual information and register callbacks for
  199. *various application events.
  200. *
  201. *Registrars are obtained from a `FlutterPluginRegistry` which keeps track of
  202. *the identity of registered plugins and provides basic support for cross-plugin
  203. *coordination.
  204. */
  205. @protocol FlutterPluginRegistrar <NSObject>
  206. /**
  207. * Returns a `FlutterBinaryMessenger` for creating Dart/iOS communication
  208. * channels to be used by the plugin.
  209. *
  210. * @return The messenger.
  211. */
  212. - (NSObject<FlutterBinaryMessenger>*)messenger;
  213. /**
  214. * Returns a `FlutterTextureRegistry` for registering textures
  215. * provided by the plugin.
  216. *
  217. * @return The texture registry.
  218. */
  219. - (NSObject<FlutterTextureRegistry>*)textures;
  220. /**
  221. * Registers a `FlutterPlatformViewFactory` for creation of platform views.
  222. *
  223. * Plugins expose `UIView` for embedding in Flutter apps by registering a view factory.
  224. *
  225. * @param factory The view factory that will be registered.
  226. * @param factoryId A unique identifier for the factory, the Dart code of the Flutter app can use
  227. * this identifier to request creation of a `UIView` by the registered factory.
  228. */
  229. - (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
  230. withId:(NSString*)factoryId;
  231. /**
  232. * Publishes a value for external use of the plugin.
  233. *
  234. * Plugins may publish a single value, such as an instance of the
  235. * plugin's main class, for situations where external control or
  236. * interaction is needed.
  237. *
  238. * The published value will be available from the `FlutterPluginRegistry`.
  239. * Repeated calls overwrite any previous publication.
  240. *
  241. * @param value The value to be published.
  242. */
  243. - (void)publish:(NSObject*)value;
  244. /**
  245. * Registers the plugin as a receiver of incoming method calls from the Dart side
  246. * on the specified `FlutterMethodChannel`.
  247. *
  248. * @param delegate The receiving object, such as the plugin's main class.
  249. * @param channel The channel
  250. */
  251. - (void)addMethodCallDelegate:(NSObject<FlutterPlugin>*)delegate
  252. channel:(FlutterMethodChannel*)channel;
  253. /**
  254. * Registers the plugin as a receiver of `UIApplicationDelegate` calls.
  255. *
  256. * @param delegate The receiving object, such as the plugin's main class.
  257. */
  258. - (void)addApplicationDelegate:(NSObject<FlutterPlugin>*)delegate;
  259. /**
  260. * Returns the file name for the given asset.
  261. * The returned file name can be used to access the asset in the application's main bundle.
  262. *
  263. * @param asset The name of the asset. The name can be hierarchical.
  264. * @return the file name to be used for lookup in the main bundle.
  265. */
  266. - (NSString*)lookupKeyForAsset:(NSString*)asset;
  267. /**
  268. * Returns the file name for the given asset which originates from the specified package.
  269. * The returned file name can be used to access the asset in the application's main bundle.
  270. *
  271. *
  272. * @param asset The name of the asset. The name can be hierarchical.
  273. * @param package The name of the package from which the asset originates.
  274. * @return the file name to be used for lookup in the main bundle.
  275. */
  276. - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package;
  277. @end
  278. /**
  279. * A registry of Flutter iOS plugins.
  280. *
  281. * Plugins are identified by unique string keys, typically the name of the
  282. * plugin's main class. The registry tracks plugins by this key, mapping it to
  283. * a value published by the plugin during registration, if any. This provides a
  284. * very basic means of cross-plugin coordination with loose coupling between
  285. * unrelated plugins.
  286. *
  287. * Plugins typically need contextual information and the ability to register
  288. * callbacks for various application events. To keep the API of the registry
  289. * focused, these facilities are not provided directly by the registry, but by
  290. * a `FlutterPluginRegistrar`, created by the registry in exchange for the unique
  291. * key of the plugin.
  292. *
  293. * There is no implied connection between the registry and the registrar.
  294. * Specifically, callbacks registered by the plugin via the registrar may be
  295. * relayed directly to the underlying iOS application objects.
  296. */
  297. @protocol FlutterPluginRegistry <NSObject>
  298. /**
  299. * Returns a registrar for registering a plugin.
  300. *
  301. * @param pluginKey The unique key identifying the plugin.
  302. */
  303. - (NSObject<FlutterPluginRegistrar>*)registrarForPlugin:(NSString*)pluginKey;
  304. /**
  305. * Returns whether the specified plugin has been registered.
  306. *
  307. * @param pluginKey The unique key identifying the plugin.
  308. * @return `YES` if `registrarForPlugin` has been called with `pluginKey`.
  309. */
  310. - (BOOL)hasPlugin:(NSString*)pluginKey;
  311. /**
  312. * Returns a value published by the specified plugin.
  313. *
  314. * @param pluginKey The unique key identifying the plugin.
  315. * @return An object published by the plugin, if any. Will be `NSNull` if
  316. * nothing has been published. Will be `nil` if the plugin has not been
  317. * registered.
  318. */
  319. - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey;
  320. @end
  321. /**
  322. * Implement this in the `UIAppDelegate` of your app to enable Flutter plugins to register
  323. * themselves to the application life cycle events.
  324. */
  325. @protocol FlutterAppLifeCycleProvider
  326. - (void)addApplicationLifeCycleDelegate:(NSObject<FlutterPlugin>*)delegate;
  327. @end
  328. NS_ASSUME_NONNULL_END;
  329. #endif // FLUTTER_FLUTTERPLUGIN_H_