2012-09-07 32 views
4

我试着去找到一个功能,让我打印使用AirPrint功能。功能发送图像到支持AirPrint

我有一个按钮btnPrint,按下时,应打印myPic.jpg到默认AirPrint的设备。但我无法弄清楚是否有这样的功能。

我找不到在Xcode上的AirPrint大量的文档资料。

+3

这个问题是不相关的Xcode。 – 2012-09-07 13:32:12

回答

4

苹果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]; 

} 
+0

嗨,我正在实施相同的。但我想知道是否有任何方法可以知道打印已完成?有没有任何委托方法? –