override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)//pub 插件通信组册
let registrar = self.registrar(forPlugin: "FlutterIosPay")!//1、创建通信组册
//组册原生组建
//let factory = MyPlatformViewFactory(messenger: registrar.messenger())
//registrar.register(factory, withId: "FlutterIosPay/custom_platform_view")
//2、组册通信
Flutter2OCBridge.register(with: registrar);
}
.h
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface Flutter2OCBridge : NSObject<FlutterPlugin>
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar;
@end
NS_ASSUME_NONNULL_END
.m
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar{
channel = [FlutterMethodChannel methodChannelWithName:@"Paul" binaryMessenger:[registrar messenger]];
Flutter2OCBridge *instance = [[Flutter2OCBridge alloc]init];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if([call.method isEqualToString:@"flutter2native"]){
//方法调用
[Flutter2OCBridge getFlutter2native:call.arguments result:result];
}
}
flutter端调用
Future iosFlutter2native(Map map) async {
const platform = const MethodChannel('Paul');
var result;
try {
//方法跟参数
result = await platform.invokeMethod('flutter2native',map);
} on PlatformException catch (e) {
debugPrint(e.toString());
}
return result;
}