Update plugin interface with some breaking changes

This commit is contained in:
Sebastián Katzer
2019-01-25 12:42:22 +01:00
parent 98b5d32527
commit ce27a883ab
7 changed files with 321 additions and 169 deletions

View File

@@ -23,11 +23,12 @@
@interface APPPrinter : CDVPlugin <UIPrintInteractionControllerDelegate>
// Find out whether printing is supported on this platform
- (void) check:(CDVInvokedUrlCommand *)command;
// Displays system interface for selecting a printer
- (void) utis:(CDVInvokedUrlCommand *)command;
- (void) pick:(CDVInvokedUrlCommand *)command;
// Prints the content
- (void) print:(CDVInvokedUrlCommand *)command;
@end

View File

@@ -42,22 +42,30 @@
- (void) check:(CDVInvokedUrlCommand *)command
{
[self.commandDelegate runInBackground:^{
BOOL res = NO;
if (command.arguments.count == 0)
{
res = UIPrintInteractionController.isPrintingAvailable;
}
else
{
res = [APPPrinterItem canPrintURL:command.arguments[0]];
}
BOOL res = [APPPrinterItem canPrintURL:command.arguments[0]];
[self sendResultWithMessageAsBool:res
callbackId:command.callbackId];
}];
}
/*
* List all printable document types (utis).
*/
- (void) utis:(CDVInvokedUrlCommand *)command
{
[self.commandDelegate runInBackground:^{
NSSet *utis = UIPrintInteractionController.printableUTIs;
CDVPluginResult* result =
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArray:utis.allObjects];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
}
/**
* Displays system interface for selecting a printer.
*/

View File

@@ -23,6 +23,6 @@
+ (id) ItemFromURL:(NSString *)url;
+ (BOOL) canPrintURL:(NSString *)url;
+ (BOOL) canPrintURL:(nullable NSString *)url;
@end

View File

@@ -45,9 +45,12 @@
*
* @return true if its able to render the content of the file.
*/
+ (BOOL) canPrintURL:(NSString *)url
+ (BOOL) canPrintURL:(nullable NSString *)url
{
if (![NSURL URLWithString:url]) return YES;
if (![NSURL URLWithString:url])
{
return UIPrintInteractionController.isPrintingAvailable;
}
id item = [self ItemFromURL:url];

View File

@@ -21,6 +21,6 @@
@interface APPPrinterUnit : NSObject
+ (double) convert:(NSString *)unit;
+ (double) convert:(nullable NSString *)unit;
@end

View File

@@ -23,8 +23,11 @@
@implementation APPPrinterUnit
+ (double) convert:(NSString *)unit
+ (double) convert:(nullable NSString *)unit
{
if ([unit isEqual:[NSNull null]])
return 1.0;
if ([unit isEqualToString:@"in"])
return 72.0;