override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)//pub 插件通信組冊(cè)
let registrar = self.registrar(forPlugin: "FlutterIosPay")!//1、創(chuàng)建通信組冊(cè)
//組冊(cè)原生組建
//let factory = MyPlatformViewFactory(messenger: registrar.messenger())
//registrar.register(factory, withId: "FlutterIosPay/custom_platform_view")
//2坎怪、組冊(cè)通信
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"]){
//方法調(diào)用
[Flutter2OCBridge getFlutter2native:call.arguments result:result];
}
}
flutter端調(diào)用
Future iosFlutter2native(Map map) async {
const platform = const MethodChannel('Paul');
var result;
try {
//方法跟參數(shù)
result = await platform.invokeMethod('flutter2native',map);
} on PlatformException catch (e) {
debugPrint(e.toString());
}
return result;
}