Cache UIPrinter (#128)
* Cache UIPrinter This speeds up printing time from 25 seconds to < 5 * Switching to isEqualToString
This commit is contained in:
parent
99f50db26e
commit
d2486217f0
@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
@interface APPPrinter : CDVPlugin <UIWebViewDelegate>
|
@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
|
// Find out whether printing is supported on this platform
|
||||||
- (void) check:(CDVInvokedUrlCommand*)command;
|
- (void) check:(CDVInvokedUrlCommand*)command;
|
||||||
// Displays system interface for selecting a printer
|
// Displays system interface for selecting a printer
|
||||||
|
@ -195,7 +195,14 @@
|
|||||||
printer:(NSString*)printerId
|
printer:(NSString*)printerId
|
||||||
{
|
{
|
||||||
NSURL* url = [NSURL URLWithString: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:
|
[controller printToPrinter:printer completionHandler:
|
||||||
^(UIPrintInteractionController *ctrl, BOOL ok, NSError *e) {
|
^(UIPrintInteractionController *ctrl, BOOL ok, NSError *e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user