Update plugin interface with some breaking changes
This commit is contained in:
@@ -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
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
@@ -23,6 +23,6 @@
|
||||
|
||||
+ (id) ItemFromURL:(NSString *)url;
|
||||
|
||||
+ (BOOL) canPrintURL:(NSString *)url;
|
||||
+ (BOOL) canPrintURL:(nullable NSString *)url;
|
||||
|
||||
@end
|
||||
|
@@ -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];
|
||||
|
||||
|
@@ -21,6 +21,6 @@
|
||||
|
||||
@interface APPPrinterUnit : NSObject
|
||||
|
||||
+ (double) convert:(NSString *)unit;
|
||||
+ (double) convert:(nullable NSString *)unit;
|
||||
|
||||
@end
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user