我正在尝试找到一个函数,可以让我使用AirPrint打印。
我有一个按钮btnPrint,当按下它时,应该会将myPic.jpg打印到默认的AirPrint设备。但我甚至不知道是否有这样的函数。
我在xcode中找不到很多关于AirPrint的文档。
发布于 2012-09-07 21:35:20
苹果的documentation on printing可能会让你受益。
下面是来自Objective-C code for AirPrint的内容
检查是否可以打印:
if ([UIPrintInteractionController isPrintingAvailable])
{
// Available
} else {
// Not Available
}单击按钮后打印:
-(IBAction) buttonClicked: (id) sender;
{
NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@, %@",self.encoded.text, self.decoded.text];
[printBody appendFormat:@"\n\n\n\nPrinted From *myapp*"];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = self.titleLabel.text;
pic.printInfo = printInfo;
UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody];
textFormatter.startPage = 0;
textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
textFormatter.maximumContentWidth = 6 * 72.0;
pic.printFormatter = textFormatter;
[textFormatter release];
pic.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not complete because of error: %@", error);
}
};
[pic presentFromBarButtonItem:self.rightButton animated:YES completionHandler:completionHandler];
}https://stackoverflow.com/questions/12319121
复制相似问题