前言
首先这里有三个形似得英文单词registry, registrar and registrant分别对应注册局,注册商和注册人。
把它们翻译到现实的生活场景中的角色其实是一个“注册人通过注册商,更新注册信息后,注册商把信息传递给注册局进行保存”的过程。
注册人:GeneratedPluginRegistrant
注册局:[(FlutterViewController*)rootViewController pluginRegistry] == flutterEngine
注册商:FlutterEngineRegistrar
Flutter Application
flutter create -t plugin my_plugin
xcode 打开 my_plugin/example/ios路径下的 Runner工程
AppDelegate
1 | @implementation AppDelegate |
GeneratedPluginRegistrant
1 | @implementation GeneratedPluginRegistrant |
AppDelegate继承FlutterAppDelegate
FlutterAppDelegate
1 |
|
FlutterViewController
1 | - (id<FlutterPluginRegistry>)pluginRegistry { |
FlutterEngineRegistrar
1 | @implementation FlutterEngineRegistrar { |
MyPlugin
1 | @implementation MyPlugin |
FlutterMethodChannel
1 | - (instancetype)initWithName:(NSString*)name |
FlutterEngine
1 |
|
FlutterBinaryMessage
1 | /** |