|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
-
- #import <Flutter/Flutter.h>
- #import "ZhiyingCommNative.h"
- #import "ZhiyingCommNativeResult.h"
-
- @implementation ZhiyingCommNative
-
-
- static id<ZhiyingCommNativeProtocol> _delegate;
-
- + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
- FlutterMethodChannel* channel = [FlutterMethodChannel
- methodChannelWithName:@"zhiying_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<ZhiyingCommNativeProtocol>) delegate {
- _delegate = delegate;
- }
-
- @end
|