From 96f3d6f099e8fae2f79694c72374bf7cb9ed68a4 Mon Sep 17 00:00:00 2001 From: Erik Wallin Date: Mon, 29 Feb 2016 13:05:56 +0100 Subject: [PATCH] Wait for webview to finish load Big html documents is now fully loaded when UIPrintInteractionController is presented --- src/ios/APPPrinter.h | 2 +- src/ios/APPPrinter.m | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ios/APPPrinter.h b/src/ios/APPPrinter.h index 1fe2533..fb48b2a 100755 --- a/src/ios/APPPrinter.h +++ b/src/ios/APPPrinter.h @@ -23,7 +23,7 @@ #import -@interface APPPrinter : CDVPlugin +@interface APPPrinter : CDVPlugin // Prints the content - (void) print:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/APPPrinter.m b/src/ios/APPPrinter.m index f9bff4d..6ebf989 100755 --- a/src/ios/APPPrinter.m +++ b/src/ios/APPPrinter.m @@ -25,6 +25,7 @@ @interface APPPrinter () @property (retain) NSString* callbackId; +@property (retain) NSMutableDictionary* settings; @end @@ -67,21 +68,26 @@ NSArray* arguments = [command arguments]; NSString* content = [arguments objectAtIndex:0]; - NSMutableDictionary* settings = [arguments objectAtIndex:1]; + self.settings = [arguments objectAtIndex:1]; UIPrintInteractionController* controller = [self printController]; - NSString* printerId = [settings objectForKey:@"printerId"]; - - [self adjustPrintController:controller withSettings:settings]; + [self adjustPrintController:controller withSettings:self.settings]; [self loadContent:content intoPrintController:controller]; +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + UIPrintInteractionController* controller = [self printController]; + NSString* printerId = [self.settings objectForKey:@"printerId"]; + if (printerId) { [self sendToPrinter:controller printer:printerId]; } else { - CGRect rect = [self convertIntoRect:[settings objectForKey:@"bounds"]]; - + CGRect rect = [self convertIntoRect:[self.settings objectForKey:@"bounds"]]; + [self presentPrintController:controller fromRect:rect]; } } @@ -163,6 +169,7 @@ - (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller { UIWebView* page = [[UIWebView alloc] init]; + page.delegate = self; UIPrintPageRenderer* renderer = [[UIPrintPageRenderer alloc] init]; [self adjustWebView:page andPrintPageRenderer:renderer];