我正在尝试对我的 UIWebView (iOS8.1) 的内容进行 AirPrint,但我遇到了一个异常,没有详细说明问题所在。如果我在 Xcode 6.1 中将“全局断点状态”切换为 OFF,那么它偶尔会打印,尽管有时页面是空白的。我还在使用最新安装的 Printopia 打印到 iMac。
是否还有其他人在 iOS8 中遇到 AirPrinting 问题?下面的代码是否存在可能导致此问题的问题?
// AirPrint 功能
-(void)printBid {
if ([UIPrintInteractionController isPrintingAvailable]) { // 检查我们是否可以打印
// 使用 UIPrintInteractionController 打印网页视图内容
// 这会在全局断点状态设置为 On 时生成异常,但在 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];
}
}
提前感谢您的帮助。