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

ZhiyingCommNative.m 2.2 KiB

пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 if ([@"notifyInitSuccess" isEqualToString:call.method]) {
  42. if ([_delegate respondsToSelector:@selector(notifyInitSuccess:)]) {
  43. [_delegate notifyInitSuccess:call.arguments];
  44. }
  45. result(@{@"success": @"1"});
  46. } else{
  47. result(FlutterMethodNotImplemented);
  48. }
  49. }
  50. + (void)regist:(id<ZhiyingCommNativeProtocol>) delegate {
  51. _delegate = delegate;
  52. }
  53. @end