In my iOS application, I have the following code that is used for AirPrinting a simple 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]; } }
When I start my project (to check it), this is the error I get in the Output Debugger window when I click "Print" in the UIPrintInteractionController:
Simulated\032InkJet\ 032@ \032USER\032NAME\032iMac._ipp._tcp.local.: startJob: Unable to connect to printd: Connection refused
I get this error in iOS 5.1 simulator using print simulator. Why am I getting this error? I have a feeling that this is due to the way I use the print simulator. A.
Any help is appreciated, and as a wonderful side, does anyone know how to display a UIPrintInteraction controller from a regular UIButton on an iPad instead of a BarButtonItem?
EDIT: It should be noted that AirPrint is automatically configured when using Share Sheets in iOS 6.0 +.
source share