基础库
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

ZhiyingCommNative.m 2.1 KiB

4 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 ([@"invokeMethod" isEqualToString:call.method]) {
  37. NSDictionary *dict = call.arguments;
  38. NSString *method = [dict valueForKey:@"method"];
  39. NSDictionary *params = [dict valueForKey:@"params"];
  40. if ([_delegate respondsToSelector:@selector(invokeMethod:withParams:status:)]) {
  41. [_delegate invokeMethod:method withParams: params status: ^(ZhiyingCommNativeResult *res) {
  42. result([res toDict]);
  43. }];
  44. } else {
  45. result([NativeCommandNotImp toDict]);
  46. }
  47. } else{
  48. result(FlutterMethodNotImplemented);
  49. }
  50. }
  51. + (void)regist:(id<ZhiyingCommNativeProtocol>) delegate {
  52. _delegate = delegate;
  53. }
  54. @end