我目前正在通过UIPrintInteractionController
printToPrinter
方法使用直接打印来开发应用程序,但是当我启动打印命令时,会弹出一个对话框:
打印到“ my-printer.local”。
正在联系打印机...
但是我的打印机没有任何打印命令,并且该应用程序卡在该弹出窗口中(点击“取消”按钮不执行任何操作)。
这是我的打印方法:
- (void)directPrint:(nonnull NSString*)name withPrinter:(NSURL*)printerURL {
UIPrintInteractionController* controller = [UIPrintInteractionController sharedPrintController];
[controller setDelegate:self];
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
printInfo.jobName = name;
printInfo.outputType = UIPrintInfoOutputGeneral;
controller.printInfo = printInfo;
renderer = [[PdfPrintPageRenderer alloc] init:channel];
[controller setPrintPageRenderer:renderer];
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController* printController, BOOL completed, NSError* error) {
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);
}
self->renderer = nil;
};
UIPrinter* printer = [UIPrinter printerWithURL:printerURL];
BOOL status = [controller printToPrinter:printer completionHandler:completionHandler];
NSLog(@"Print status: %d", status);
}
printerURL
来自UIPrinterPickerController
presentAnimated
方法。
status
变量为true
。
我尝试使用iPhone模拟器+打印机模拟器,这是一个方法调用的打印机日志:
[21/Feb/2019:14:40:49 +0100] [Client 46] Accepted connection from 192.168.1.131:57092 (IPv4)
[21/Feb/2019:14:40:49 +0100] [Client 46] Encrypting connection.
[21/Feb/2019:14:40:49 +0100] [Client 46] Connection from 192.168.1.131 now encrypted.
[21/Feb/2019:14:40:49 +0100] [Client 47] Accepted connection from 192.168.1.131:57093 (IPv4)
[21/Feb/2019:14:40:49 +0100] [Client 47] Encrypting connection.
[21/Feb/2019:14:40:49 +0100] [Client 47] Connection from 192.168.1.131 now encrypted.
注释1:使用UIPrintInteractionController
presentAnimated
进行打印非常有效(使用模拟器或真实设备)。
注意2::Flutter插件内部使用了以下代码。
答案 0 :(得分:0)
此问题与iOS打印功能无关,而是来自直接打印的插件实现。
有关更多信息,请参见此处:https://github.com/DavBfr/dart_pdf/issues/37
正是回调和线程的当前用法使UI无法响应。