printer example fix in ios15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WKWebView * webView = [[WKWebView alloc] initWithFrame:CGRectZero]; | |
| [webView loadHTMLString:markup baseURL:nil]; // assuming some html loaded into markup for the printer | |
| UIViewPrintFormatter *formatter = webView.viewPrintFormatter; | |
| UIPrintInteractionController *printInteractionController = [UIPrintInteractionController sharedPrintController]; | |
| [printInteractionController setPrintFormatter:formatter]; | |
| UIPrintInfo *printInfo = [UIPrintInfo printInfo]; | |
| printInfo.duplex = UIPrintInfoDuplexNone; | |
| printInfo.outputType = UIPrintInfoOutputPhotoGrayscale; | |
| self.printer = [UIPrinter printerWithURL:url]; // assuming you already have the printer url | |
| [printInteractionController setDelegate:self]; | |
| [printInteractionController setPrintInfo:printInfo]; | |
| [self.printer contactPrinter:^(BOOL available) { | |
| if (!available) { | |
| [self printFailed]; // private handler | |
| } else { | |
| [printInteractionController printToPrinter:self.printer | |
| completionHandler:^(UIPrintInteractionController *controller, BOOL completed, NSError *error) { | |
| if ( error ) { | |
| NSLog(@"Airprint error: %@", error); | |
| [self printFailed]; // private handler | |
| } else { | |
| // success case here | |
| } | |
| controller.delegate = nil; | |
| }]; | |
| } | |
| }]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment