CompdfkitFlutterPlugin.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #import "CompdfkitFlutterPlugin.h"
  2. #import "FLNativeView.h"
  3. #import <ComPDFKit/ComPDFKit.h>
  4. @implementation CompdfkitFlutterPlugin
  5. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  6. FlutterMethodChannel* channel = [FlutterMethodChannel
  7. methodChannelWithName:@"com.compdfkit.flutter.plugin"
  8. binaryMessenger:[registrar messenger]];
  9. CompdfkitFlutterPlugin* instance = [[CompdfkitFlutterPlugin alloc] init];
  10. [registrar addMethodCallDelegate:instance channel:channel];
  11. FLNativeViewFactory* factory =
  12. [[FLNativeViewFactory alloc] initWithMessenger:registrar.messenger];
  13. [registrar registerViewFactory:factory withId:@"com.compdfkit.flutter.pdfviewer"];
  14. }
  15. - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  16. if ([@"sdk_version_code" isEqualToString:call.method]) {
  17. result([CPDFKit sharedInstance].versionString);
  18. } else if ([@"init_sdk" isEqualToString:call.method]) {
  19. NSDictionary *initInfo = (NSDictionary *)call.arguments;
  20. NSString *key = initInfo[@"key"] ?: @"";
  21. NSString *secret = initInfo[@"secret"] ?: @"";
  22. [CPDFKit setLicenseKey:key secret:secret];
  23. } else if ([@"sdk_build_tag" isEqualToString:call.method]) {
  24. result([@"iOS build tag:" stringByAppendingFormat:@"%ld", [CPDFKit sharedInstance].buildNumber]);
  25. } else {
  26. result(FlutterMethodNotImplemented);
  27. }
  28. }
  29. @end