基础库
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ZhiyingCommNative.m 2.0 KiB

pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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