基础库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

63 satır
2.2 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 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