我想知道是否有一种方法可以在不使用 UIPrintInteractionController 的情况下从 ios 应用程序打印?因为它只支持空中打印兼容的打印机。
通过使用以下方法,我成功实现了 Air print 打印:
NSString *path = [selectedForms objectAtIndex:[sender tag]];
NSData *dataFromPath = [NSData dataWithContentsOfFile:path];
UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
if(printController && [UIPrintInteractionController canPrintData:dataFromPath]) {
printController.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
printController.printingItem = dataFromPath;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
[printController presentFromRect:sender.frame inView:sender.superview animated:YES completionHandler:completionHandler];
} else {
NSLog(@"Your device is not configured for printing");
}