我的代码是:
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
NSString *url=[[req URL] absoluteString];
pi.jobName = url;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.delegate=self;
pic.showsPageRange = YES;
pic.printFormatter = self.webView.viewPrintFormatter;
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[pic presentFromRect:CGRectMake(64, 64, self.view.frame.size.width, self.view.frame.size.height-64) inView:self.view animated:YES completionHandler:^(UIPrintInteractionController* pic2, BOOL completed, NSError* error) {
}];
});
它显示得很好,但是当单击取消按钮以关闭视图时,它会因消息而崩溃:
试图从除主线程或 web 线程之外的线程获取 web lock。这可能是从辅助线程调用 UIKit 的结果。现在崩溃