0

我编写了在 iPad 上打印的代码,并且检查了不同的文档。我的代码看起来正确,但是当控制器出现并单击取消时,它会因以下错误而崩溃:尝试从主线程或 Web 线程以外的线程获取 Web 锁。这可能是从辅助线程调用 UIKit 的结果。现在崩溃...

我尝试添加一个 dispatch_async 但没有帮助。这是我的代码:

UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = self.title;

    
UIPrintInteractionController *pc = [UIPrintInteractionController sharedPrintController];
pc.delegate = (id <UIPrintInteractionControllerDelegate>)self;
pc.printInfo = printInfo;

UIViewPrintFormatter *printFormatter = [self.webView viewPrintFormatter];
printFormatter.startPage = 0;
pc.printFormatter = printFormatter;



__weak SnaglistPrintViewController *weakSelf = self;

UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed,
  NSError *error) {
    dispatch_async( dispatch_get_main_queue (), ^{
    NSLog(@"Handler completed: %d", completed);
            if (!completed && error) {
              NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, (unsigned int)error.code);
            }
            else {
                [weakSelf back];
            }
    } );
    };

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    [pc presentFromRect:CGRectZero inView:self.view animated:YES completionHandler:completionHandler];


}
4

0 回答 0