取消时 UIPrintInteractionController 崩溃

问题描述

我编码以在 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];


}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)