在我的iOS应用程序中,我有下面的代码用于AirPrinting (一个简单的NSString )。
#pragma mark - Print
-(IBAction)print:(id)sender {
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"Message";
pic.printInfo = printInfo;
UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc]initWithText:self.Message.text];
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;
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);
}
};
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[pic presentFromBarButtonItem:sender animated:YES completionHandler:completionHandler];
} else {
[pic presentAnimated:YES completionHandler:completionHandler];
}
}当我运行我的项目时(为了测试它),当我点击UIPrintInteractionController上的"Print“时,在Output窗口中会出现这样的错误:
Simulated\032InkJet\032@\032USER\032NAME\032iMac._ipp._tcp.local.: startJob: Unable to connect to printd: Connection refused我在使用打印模拟器的iOS 5.1模拟器中得到了这个错误。,为什么我会有这个错误?,我有一种感觉,它与我如何使用打印模拟器有关。
任何帮助都是值得赞赏的,顺便提一句,是否有人知道如何从UIPrintInteraction上的普通UIButton (而不是BarButtonItem )显示iPad控制器?
编辑:应该注意,AirPrint是在iOS 6.0+中使用共享表时自动设置的。
发布于 2012-08-04 02:39:52
我也有同样的问题,基本上mincemeat的回答解决了这个问题。不过,我还是得先跳过几圈。最终是某种类型的文件权限问题。
我做了以下工作(注意,需要管理员访问):
/private/var/tmp/
的形式在预览中打开。
我希望这能为你解决问题,或者至少给你指明正确的方向。祝好运。
发布于 2012-04-15 16:32:06
尝试移除
/私有/var/tmp/printd
发布于 2015-06-14 22:03:57
我有打印机模拟器停止为我工作,并没有给我任何错误。我尝试了不同的模拟器,重新设置它们,重新启动计算机,如上面提到的杀死printd,以及其他事情。
最后,为我修复的是改变我的网络连接:当时,我有一个无线网络电缆(通过雷电)连接到我的macbook --两个wifi +以太网连接在同一个网络上。我弹出以太网电缆,它立刻又开始工作了。
谢谢苹果,我在哪里可以拿回我的20分钟:)
https://stackoverflow.com/questions/10163092
复制相似问题