首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将图像发送到AirPrint的函数

将图像发送到AirPrint的函数
EN

Stack Overflow用户
提问于 2012-09-07 21:30:56
回答 1查看 1.6K关注 0票数 4

我正在尝试找到一个函数,可以让我使用AirPrint打印。

我有一个按钮btnPrint,当按下它时,应该会将myPic.jpg打印到默认的AirPrint设备。但我甚至不知道是否有这样的函数。

我在xcode中找不到很多关于AirPrint的文档。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-07 21:35:20

苹果的documentation on printing可能会让你受益。

下面是来自Objective-C code for AirPrint的内容

检查是否可以打印:

代码语言:javascript
复制
if ([UIPrintInteractionController isPrintingAvailable])
{
    // Available
} else {
    // Not Available
}

单击按钮后打印:

代码语言:javascript
复制
-(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];

}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12319121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档