Merge pull request #76 from ErikWallin/master
Wait for webview to finish load content
This commit is contained in:
commit
1d5800c694
@ -23,7 +23,7 @@
|
|||||||
#import <Cordova/CDVPlugin.h>
|
#import <Cordova/CDVPlugin.h>
|
||||||
|
|
||||||
|
|
||||||
@interface APPPrinter : CDVPlugin
|
@interface APPPrinter : CDVPlugin <UIWebViewDelegate>
|
||||||
|
|
||||||
// Prints the content
|
// Prints the content
|
||||||
- (void) print:(CDVInvokedUrlCommand*)command;
|
- (void) print:(CDVInvokedUrlCommand*)command;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
@interface APPPrinter ()
|
@interface APPPrinter ()
|
||||||
|
|
||||||
@property (retain) NSString* callbackId;
|
@property (retain) NSString* callbackId;
|
||||||
|
@property (retain) NSMutableDictionary* settings;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -67,21 +68,26 @@
|
|||||||
|
|
||||||
NSArray* arguments = [command arguments];
|
NSArray* arguments = [command arguments];
|
||||||
NSString* content = [arguments objectAtIndex:0];
|
NSString* content = [arguments objectAtIndex:0];
|
||||||
NSMutableDictionary* settings = [arguments objectAtIndex:1];
|
self.settings = [arguments objectAtIndex:1];
|
||||||
|
|
||||||
UIPrintInteractionController* controller = [self printController];
|
UIPrintInteractionController* controller = [self printController];
|
||||||
|
|
||||||
NSString* printerId = [settings objectForKey:@"printerId"];
|
[self adjustPrintController:controller withSettings:self.settings];
|
||||||
|
|
||||||
[self adjustPrintController:controller withSettings:settings];
|
|
||||||
[self loadContent:content intoPrintController:controller];
|
[self loadContent:content intoPrintController:controller];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)webViewDidFinishLoad:(UIWebView *)webView
|
||||||
|
{
|
||||||
|
UIPrintInteractionController* controller = [self printController];
|
||||||
|
NSString* printerId = [self.settings objectForKey:@"printerId"];
|
||||||
|
|
||||||
if (printerId) {
|
if (printerId) {
|
||||||
[self sendToPrinter:controller printer:printerId];
|
[self sendToPrinter:controller printer:printerId];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CGRect rect = [self convertIntoRect:[settings objectForKey:@"bounds"]];
|
CGRect rect = [self convertIntoRect:[self.settings objectForKey:@"bounds"]];
|
||||||
|
|
||||||
[self presentPrintController:controller fromRect:rect];
|
[self presentPrintController:controller fromRect:rect];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,6 +169,7 @@
|
|||||||
- (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller
|
- (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller
|
||||||
{
|
{
|
||||||
UIWebView* page = [[UIWebView alloc] init];
|
UIWebView* page = [[UIWebView alloc] init];
|
||||||
|
page.delegate = self;
|
||||||
UIPrintPageRenderer* renderer = [[UIPrintPageRenderer alloc] init];
|
UIPrintPageRenderer* renderer = [[UIPrintPageRenderer alloc] init];
|
||||||
|
|
||||||
[self adjustWebView:page andPrintPageRenderer:renderer];
|
[self adjustWebView:page andPrintPageRenderer:renderer];
|
||||||
|
Loading…
Reference in New Issue
Block a user