#import "CompdfkitFlutterPlugin.h" #import #import "CPDFViewController.h" @interface CompdfkitFlutterPlugin () @end @implementation CompdfkitFlutterPlugin + (void)registerWithRegistrar:(NSObject*)registrar { FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"com.compdfkit.flutter.plugin" binaryMessenger:[registrar messenger]]; CompdfkitFlutterPlugin* instance = [[CompdfkitFlutterPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { if ([@"sdk_version_code" isEqualToString:call.method]) { result([CPDFKit sharedInstance].versionString); } else if ([@"init_sdk" isEqualToString:call.method]) { NSDictionary *initInfo = (NSDictionary *)call.arguments; NSString *key = initInfo[@"key"] ?: @""; [CPDFKit verifyWithKey:key]; } else if ([@"sdk_build_tag" isEqualToString:call.method]) { result([@"iOS build tag:" stringByAppendingFormat:@"%ld", [CPDFKit sharedInstance].buildNumber]); } else if ([@"openDocument" isEqualToString:call.method]){ NSDictionary *initInfo = (NSDictionary *)call.arguments; NSString *path = initInfo[@"document"] ?: @""; UIViewController *tRootViewControl = [UIApplication sharedApplication].keyWindow.rootViewController; if ([tRootViewControl presentedViewController]) { tRootViewControl = [tRootViewControl presentedViewController]; } CPDFConfiguration *configuration = [[CPDFConfiguration alloc] init]; CNavBarButtonItem *thumbnail = [[CNavBarButtonItem alloc]initWithViewLeftBarButtonItem:CPDFViewBarLeftButtonItem_Thumbnail]; CNavBarButtonItem *back = [[CNavBarButtonItem alloc]initWithViewLeftBarButtonItem:CPDFViewBarLeftButtonItem_Back]; CNavBarButtonItem *search = [[CNavBarButtonItem alloc]initWithViewRightBarButtonItem:CPDFViewBarRightButtonItem_Search]; CNavBarButtonItem *bota = [[CNavBarButtonItem alloc]initWithViewRightBarButtonItem:CPDFViewBarRightButtonItem_Bota]; CNavBarButtonItem *more = [[CNavBarButtonItem alloc]initWithViewRightBarButtonItem:CPDFViewBarRightButtonItem_More]; configuration.showleftItems = @[back,thumbnail]; configuration.showRightItems = @[search,bota,more]; CPDFViewController *pdfViewController = [[CPDFViewController alloc] initWithFilePath:path password:nil configuration:configuration]; pdfViewController.delegate = self; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:pdfViewController]; navigationController.modalPresentationStyle = UIModalPresentationFullScreen; [tRootViewControl presentViewController:navigationController animated:YES completion:nil]; } else if ([@"getTemporaryDirectory" isEqualToString:call.method]){ result([self getTemporaryDirectory]); } else { result(FlutterMethodNotImplemented); } } - (NSString*)getTemporaryDirectory { NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); return paths.firstObject; } #pragma mark - CPDFViewBaseControllerDelete - (void)PDFViewBaseControllerDissmiss:(CPDFViewBaseController *)baseControllerDelete { [baseControllerDelete dismissViewControllerAnimated:YES completion:nil]; } @end