// // ZhiyingCommNative.m // hairuyi_flutter_comm // // Created by Weller on 2020/5/16. // #import #import "ZhiyingCommNative.h" #import "ZhiyingCommNativeResult.h" @implementation ZhiyingCommNative static id _delegate; + (void)registerWithRegistrar:(NSObject*)registrar { FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"hairuyi_flutter_comm://method" binaryMessenger:[registrar messenger]]; ZhiyingCommNative* instance = [[ZhiyingCommNative alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { if ([@"openPage" isEqualToString:call.method]) { if ([_delegate respondsToSelector:@selector(openPage:)]) { [_delegate openPage:call.arguments]; } result(@{@"success": @"1"}); } else if ([@"openNativePage" isEqualToString:call.method]) { if ([_delegate respondsToSelector:@selector(openNativePage:)]) { [_delegate openNativePage:call.arguments]; } result(@{@"success": @"1"}); } else if ([@"getSetting" isEqualToString:call.method]) { NSDictionary *setting = @{}; if ([_delegate respondsToSelector:@selector(getSetting)]) { setting = [_delegate getSetting]; } result(setting); } else if ([@"invokeMethod" isEqualToString:call.method]) { NSDictionary *dict = call.arguments; NSString *method = [dict valueForKey:@"method"]; NSDictionary *params = [dict valueForKey:@"params"]; if ([_delegate respondsToSelector:@selector(invokeMethod:withParams:status:)]) { [_delegate invokeMethod:method withParams: params status: ^(ZhiyingCommNativeResult *res) { result([res toDict]); }]; } else { result([NativeCommandNotImp toDict]); } } else{ result(FlutterMethodNotImplemented); } } + (void)regist:(id) delegate { _delegate = delegate; } @end