以编程方式从ipad向wifi打印机发送数据

时间:2012-01-06 06:26:55

标签: objective-c ipad ios5 wifi printers

我正在创建一个ipad应用程序,我想以编程方式将数据发送到wifi打印机。是否有任何API或示例代码可用于实现此目的?

感谢。

2 个答案:

答案 0 :(得分:1)

我认为正常的打印API将使用AirPrint完成此任务。 http://developer.apple.com/library/IOs/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Printing/Printing.html

此外,还有一个名为Printopia的优秀应用程序,允许您的Mac作为AirPrint主机:http://www.ecamm.com/mac/printopia/

答案 1 :(得分:0)

UIPrintInteractionController * pic = [UIPrintInteractionController sharedPrintController];

if(pic&& [UIPrintInteractionController canPrintData:self.myPDFData]){

pic.delegate = self;

UIPrintInfo *printInfo = [UIPrintInfo printInfo];

printInfo.outputType = UIPrintInfoOutputGeneral;

printInfo.jobName = @"PrintPdf";

printInfo.duplex = UIPrintInfoDuplexLongEdge;

pic.printInfo = printInfo;

pic.showsPageRange = YES;

pic.printingItem = self.myPDFData;

void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =

^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {

    if (!completed && error)

        NSLog(@"FAILED! due to error in domain %@ with error code %ld",

              error.domain, (long)error.code);
};
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

    [pic presentFromRect:self.printButton.frame inView:self.view animated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {
    }];

} else {
    [pic presentAnimated:YES completionHandler:completionHandler];
}

}