diff --git a/src/android/Printer.java b/src/android/Printer.java index 58fbd90..c55128e 100644 --- a/src/android/Printer.java +++ b/src/android/Printer.java @@ -117,8 +117,8 @@ public class Printer extends CordovaPlugin { command = callback; - if (action.equalsIgnoreCase("isAvailable")) { - isAvailable(); + if (action.equalsIgnoreCase("check")) { + check(); return true; } @@ -139,7 +139,7 @@ public class Printer extends CordovaPlugin { * Informs if the device is able to print documents. * A Internet connection is required to load the cloud print dialog. */ - private void isAvailable () { + private void check () { cordova.getThreadPool().execute(new Runnable() { @Override public void run() { diff --git a/src/ios/APPPrinter.h b/src/ios/APPPrinter.h index 8ba65b1..a2d1dd1 100755 --- a/src/ios/APPPrinter.h +++ b/src/ios/APPPrinter.h @@ -25,11 +25,11 @@ @interface APPPrinter : CDVPlugin -// Prints the content -- (void) print:(CDVInvokedUrlCommand*)command; // Find out whether printing is supported on this platform -- (void) isAvailable:(CDVInvokedUrlCommand*)command; +- (void) check:(CDVInvokedUrlCommand*)command; // Displays system interface for selecting a printer - (void) pick:(CDVInvokedUrlCommand*)command; +// Prints the content +- (void) print:(CDVInvokedUrlCommand*)command; @end diff --git a/src/ios/APPPrinter.m b/src/ios/APPPrinter.m index 69a508c..798038b 100755 --- a/src/ios/APPPrinter.m +++ b/src/ios/APPPrinter.m @@ -41,7 +41,7 @@ * @param {Function} callback * A callback function to be called with the result */ -- (void) isAvailable:(CDVInvokedUrlCommand*)command +- (void) check:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ CDVPluginResult* pluginResult; @@ -94,13 +94,13 @@ return; } _callbackId = command.callbackId; - + NSArray* arguments = [command arguments]; NSMutableDictionary* settings = [arguments objectAtIndex:0]; - + NSArray* bounds = [settings objectForKey:@"bounds"]; CGRect rect = [self convertIntoRect:bounds]; - + [self presentPrinterPicker:rect]; } @@ -140,11 +140,11 @@ - (BOOL) isPrintingAvailable { Class controllerCls = NSClassFromString(@"UIPrintInteractionController"); - + if (!controllerCls) { return NO; } - + return [self printController] && [UIPrintInteractionController isPrintingAvailable]; } @@ -165,7 +165,7 @@ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:ok]; - + [self.commandDelegate sendPluginResult:pluginResult callbackId:_callbackId]; }]; @@ -176,7 +176,7 @@ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:ok]; - + [self.commandDelegate sendPluginResult:pluginResult callbackId:_callbackId]; }]; @@ -196,13 +196,13 @@ { NSURL* url = [NSURL URLWithString:printerId]; UIPrinter* printer = [UIPrinter printerWithURL:url]; - + [controller printToPrinter:printer completionHandler: ^(UIPrintInteractionController *ctrl, BOOL ok, NSError *e) { CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:ok]; - + [self.commandDelegate sendPluginResult:pluginResult callbackId:_callbackId]; }]; @@ -218,7 +218,7 @@ { UIPrinterPickerController* controller = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil]; - + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [controller presentFromRect:rect inView:self.webView animated:YES completionHandler: ^(UIPrinterPickerController *ctrl, BOOL userDidSelect, NSError *e) { @@ -248,18 +248,18 @@ { CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT]; - + if (userDidSelect) { UIPrinter* printer = ctrl.selectedPrinter; - + [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printer]; - + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:printer.URL.absoluteString]; } - + [self.commandDelegate sendPluginResult:pluginResult callbackId:_callbackId]; } @@ -301,9 +301,9 @@ if ([[settings objectForKey:@"graystyle"] boolValue]) { outputType = UIPrintInfoOutputGrayscale; } - + outputType += [[settings objectForKey:@"border"] boolValue] ? 0 : 1; - + if ([[settings objectForKey:@"duplex"] isEqualToString:@"long"]) { duplexMode = UIPrintInfoDuplexLongEdge; } else @@ -340,7 +340,7 @@ UIViewPrintFormatter* formatter = [page viewPrintFormatter]; [renderer addPrintFormatter:formatter startingAtPageAtIndex:0]; - + page.delegate = self; if ([NSURL URLWithString:content]) { diff --git a/src/windows/PrinterProxy.js b/src/windows/PrinterProxy.js index a89a153..725b1cd 100644 --- a/src/windows/PrinterProxy.js +++ b/src/windows/PrinterProxy.js @@ -34,7 +34,7 @@ var Printing = Windows.Graphics.Printing, * @param {Array} args * Interface arguments */ -exports.isAvailable = function (success, fail, args) { +exports.check = function (success, fail, args) { success(MSApp.hasOwnProperty('getHtmlPrintDocumentSourceAsync'), 0); }; diff --git a/www/printer.js b/www/printer.js index 71d7ed3..9b1c797 100755 --- a/www/printer.js +++ b/www/printer.js @@ -54,10 +54,17 @@ exports.getDefaults = function () { * * @return {Boolean} */ -exports.isAvailable = function (callback, scope) { +exports.check = function (callback, scope) { var fn = this._createCallbackFn(callback); - exec(fn, null, 'Printer', 'isAvailable', []); + exec(fn, null, 'Printer', 'check', []); +}; + +/** + * @deprecated API call. Use `check` instead! + */ +exports.isAvailable = function () { + exports.check.apply(exports, arguments); }; /**