基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

71 lines
2.4 KiB

  1. //
  2. // ZhiyingCommNative.m
  3. // hairuyi_flutter_comm
  4. //
  5. // Created by Weller on 2020/5/16.
  6. //
  7. #import <Flutter/Flutter.h>
  8. #import "ZhiyingCommNative.h"
  9. #import "ZhiyingCommNativeResult.h"
  10. @implementation ZhiyingCommNative
  11. static id<ZhiyingCommNativeProtocol> _delegate;
  12. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  13. FlutterMethodChannel* channel = [FlutterMethodChannel
  14. methodChannelWithName:@"hairuyi_flutter_comm://method"
  15. binaryMessenger:[registrar messenger]];
  16. ZhiyingCommNative* instance = [[ZhiyingCommNative alloc] init];
  17. [registrar addMethodCallDelegate:instance channel:channel];
  18. }
  19. - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  20. if ([@"openPage" isEqualToString:call.method]) {
  21. if ([_delegate respondsToSelector:@selector(openPage:)]) {
  22. [_delegate openPage:call.arguments];
  23. }
  24. result(@{@"success": @"1"});
  25. } else if ([@"openNativePage" isEqualToString:call.method]) {
  26. if ([_delegate respondsToSelector:@selector(openNativePage:)]) {
  27. [_delegate openNativePage:call.arguments];
  28. }
  29. result(@{@"success": @"1"});
  30. } else if ([@"getSetting" isEqualToString:call.method]) {
  31. NSDictionary *setting = @{};
  32. if ([_delegate respondsToSelector:@selector(getSetting)]) {
  33. setting = [_delegate getSetting];
  34. }
  35. result(setting);
  36. } else if ([@"openWechatPay" isEqualToString:call.method]) {
  37. if ([_delegate respondsToSelector:@selector(openWechatPay:status:)]) {
  38. [_delegate openWechatPay: call.arguments status: ^(ZhiyingCommNativeResult *res) {
  39. result([res toDict]);
  40. }];
  41. } else {
  42. result([NativeCommandNotImp toDict]);
  43. }
  44. } else if ([@"invokeMethod" isEqualToString:call.method]) {
  45. NSDictionary *dict = call.arguments;
  46. NSString *method = [dict valueForKey:@"method"];
  47. NSDictionary *params = [dict valueForKey:@"params"];
  48. if ([_delegate respondsToSelector:@selector(invokeMethod:withParams:status:)]) {
  49. [_delegate invokeMethod:method withParams: params status: ^(ZhiyingCommNativeResult *res) {
  50. result([res toDict]);
  51. }];
  52. } else {
  53. result([NativeCommandNotImp toDict]);
  54. }
  55. } else{
  56. result(FlutterMethodNotImplemented);
  57. }
  58. }
  59. + (void)regist:(id<ZhiyingCommNativeProtocol>) delegate {
  60. _delegate = delegate;
  61. }
  62. @end