diff --git a/src/ios/APPPrinter.h b/src/ios/APPPrinter.h index a2d1dd1..734ccd6 100755 --- a/src/ios/APPPrinter.h +++ b/src/ios/APPPrinter.h @@ -25,6 +25,9 @@ @interface APPPrinter : CDVPlugin +// this is used to cache the uiprinter making repeated prints faster +@property (nonatomic) UIPrinter *previousPrinter; + // Find out whether printing is supported on this platform - (void) check:(CDVInvokedUrlCommand*)command; // Displays system interface for selecting a printer diff --git a/src/ios/APPPrinter.m b/src/ios/APPPrinter.m index 798038b..bba5fce 100755 --- a/src/ios/APPPrinter.m +++ b/src/ios/APPPrinter.m @@ -195,8 +195,15 @@ printer:(NSString*)printerId { NSURL* url = [NSURL URLWithString:printerId]; - UIPrinter* printer = [UIPrinter printerWithURL:url]; - + + // check to see if we have previously created this printer to reduce printing/"contacting" time + if(self.previousPrinter == nil || ![[[self.previousPrinter URL] absoluteString] isEqualToString: printerId]) { + self.previousPrinter = [UIPrinter printerWithURL:url]; + } + + UIPrinter* printer = self.previousPrinter; + + [controller printToPrinter:printer completionHandler: ^(UIPrintInteractionController *ctrl, BOOL ok, NSError *e) { CDVPluginResult* pluginResult =