我想逐个编程地打印记录。下一次打印应该等待完成上一次打印。这是代码,
更新了代码:
-(void)GetOrdersHanlder:(id)object
{
NSArray *ordersArray = (NSArray *)object;
for (int i = 0; i < ordersArray.count;i++) {
ITsOrder *orderObject = [ordersArray objectAtIndex:i];
[ordersMutableArray addObject:orderObject];
}
if (ordersMutableArray.count > 0) {
[self printOrder:[self getHtmlPrintStringForOrderObject:[ordersMutableArray objectAtIndex:0]] orderObject:[ordersMutableArray objectAtIndex:0]];
}
}
-(void)printOrder:(NSString*)htmlPrintString orderObject:(ITsOrder*)orderObject{
// dispatch_async(dispatch_get_main_queue(), ^{
printInteractionController = [UIPrintInteractionController sharedPrintController];
printInteractionController.delegate = self;
printInteractionController.showsPageRange = YES;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"InvoicePrint";
printInteractionController.printInfo = printInfo;
htmlFormatter = [[UIMarkupTextPrintFormatter alloc]
initWithMarkupText:htmlPrintString];
htmlFormatter.startPage = 0;
printInteractionController.printFormatter = htmlFormatter;
[logsMutableString appendFormat:@"\n\nPrint Started: Order No #%d",orderObject.order_no];
logsTextView.text = logsMutableString;
[printInteractionController printToPrinter:savedPrinter
completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog( @"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason );
[logsMutableString appendFormat:@"\nPrint Failed: Order No #%d",orderObject.order_no];
logsTextView.text = logsMutableString;
}else{
[logsMutableString appendFormat:@"\nPrint Successful: Order No #%d",orderObject.order_no];
logsTextView.text = logsMutableString;
}
[ordersMutableArray removeObjectAtIndex:0];
if (ordersMutableArray.count > 0 ) {
[self printOrder:[self getHtmlPrintStringForOrderObject:[ordersMutableArray objectAtIndex:0]] orderObject:[ordersMutableArray objectAtIndex:0]];
}
}];
// });
}
-
我更新了代码,调用了[self printOrder:[self getHtmlPrintStringForOrderObject:[ordersMutableArray objectAtIndex:0]] orderObject:[ordersMutableArray objectAtIndex:0]];,在完成处理程序中但获得了以下输出,
Print Started: Order No #114
Print Successful: Order No #114
Print Started: Order No #116
数组中有4个对象。但看起来,printToPrinter下次没有执行。