如何知道打印机连接是否可用? 我们也可以点击打印按钮自动只打印一份到默认打印机吗?
我尝试过以下代码..
- (void)viewDidLoad {
if (![UIPrintInteractionController isPrintingAvailable])
[myPrintButton removeFromSuperView];
// other tasks...
}
-(void)print_touchUpInside :(id)sender
{
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"print";
printInfo.duplex = UIPrintInfoDuplexLongEdge;
controller.printInfo = printInfo;
controller.showsPageRange = YES;
APLPrintPageRenderer *myRenderer = [[APLPrintPageRenderer alloc] init];
myRenderer.jobTitle = printInfo.jobName;
UIViewPrintFormatter *viewFormatter = [self.webView viewPrintFormatter];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:HEADER_FOOTER_TEXT_HEIGHT];
CGSize titleSize = [myRenderer.jobTitle sizeWithFont:font];
myRenderer.headerHeight = myRenderer.footerHeight = titleSize.height + HEADER_FOOTER_MARGIN_PADDING;
[myRenderer addPrintFormatter:viewFormatter startingAtPageAtIndex:0];
controller.printPageRenderer = myRenderer;
[controller presentAnimated:YES completionHandler:completionHandler];
}