基础库
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.
 
 
 
 
 

58 regels
2.0 KiB

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