AirPrint UIWebView content in iOS8

299 Views Asked by At

I am trying to AirPrint the contents of my UIWebView (iOS8.1) and am getting an exception with no detail as to what the problem is. If I toggle "Global Breakpoint State" to OFF in Xcode 6.1 then it occasionally prints, although sometimes the page is blank. I am also using an up-to-date installation of Printopia for printing to the iMac.

Is anyone else experiencing problems with AirPrinting in iOS8? Are there any problems with the code below that could be causing this issue?

// AirPrint functionality
-(void)printBid {
 if ([UIPrintInteractionController isPrintingAvailable]) {      // check that we can print

// Use UIPrintInteractionController to print the web view content // This generates an exception when Global Breakpoint State is set to On but seems to work when Off

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; //pic.delegate = self; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = @"QuickBids"; printInfo.duplex = UIPrintInfoDuplexLongEdge; pic.printInfo = printInfo; pic.showsPageRange = YES; UIViewPrintFormatter *formatter = [bidPreviewWebView viewPrintFormatter]; pic.printFormatter = formatter; UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { if(!completed && error){ NSLog(@"Print failed - domain: %@ error code %u", error.domain, error.code); } }; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // The device is an iPad running iPhone 3.2 or later. // iOS 8 Issue on iPad - As a workaround, I recommend delaying the presentation until the next runloop, using the following method: // http://stackoverflow.com/questions/24854802/presenting-a-view-controller-modally-from-an-action-sheets-delegate-in-ios8 dispatch_async(dispatch_get_main_queue(), ^ { [pic presentFromBarButtonItem:shareButton animated:YES completionHandler:completionHandler]; }); }else { // The device is an iPhone or iPod touch. dispatch_async(dispatch_get_main_queue(), ^ { [pic presentAnimated:YES completionHandler:completionHandler]; }); } }else { // we can't print so show an alert // show simple alert UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Printing Unavailable" message:@"You cannot print from this device." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"OK action"); }]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil]; }

}

Thanks in advance for any help.

0

There are 0 best solutions below