Cache UIPrinter (#128)

* Cache UIPrinter

This speeds up printing time from 25 seconds to < 5

* Switching to isEqualToString
This commit is contained in:
kentongray 2017-09-05 13:10:59 -05:00 committed by Sebastián Katzer
parent 99f50db26e
commit d2486217f0
2 changed files with 12 additions and 2 deletions

View File

@ -25,6 +25,9 @@
@interface APPPrinter : CDVPlugin <UIWebViewDelegate>
// 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

View File

@ -195,7 +195,14 @@
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) {