In my iOS app, I have the following code that is being 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 run my project (to test it), this is the error I get in the Output Debugger Window when I tap "Print" on the UIPrintInteractionController:
Simulated\032InkJet\032@\032USER\032NAME\032iMac._ipp._tcp.local.: startJob: Unable to connect to printd: Connection refused
I get this error in the iOS 5.1 Simulator using the Print Simulator. Why am I getting this error? I have a feeling it has to do with how I am using the Print Simulator.
Any help is appreciated, and just as a side note, does anyone know how to display the UIPrintInteraction controller from a normal UIButton on the iPad instead of a BarButtonItem?
EDIT: It should be noted that AirPrint is automatically setup when using Share Sheets in iOS 6.0+.
AirPrint requires a wireless connection to discover your printer. Make sure the printer and your Apple device are connected to the same local Wi-Fi network and check for any network-related issues. 1. On the Apple device, make sure Wi-Fi is on and there is a check mark next to the name of your local wireless network.
If an AirPrint-enabled printer isn't showing up on your iPhone, head to the printer's network settings and ensure its Wi-Fi is enabled. Most importantly, make sure the printer is connected to the same Wi-Fi network as your iPhone. If the problem persists, the printer could be blocked or blacklisted on the network.
Click [Settings/Registration] → select [Network Settings] in <Preferences> → click [AirPrint Settings]. If you are using a mobile device, such as an iPad, iPhone, or iPod touch, read "click" as "tap" in this section. Specify the required settings → click [OK].
I had the exact same problem and basically mincemeat's answer fixed the issue. However I did have to jump through a few hoops first. Ultimately it was some sort of file permissions problem.
I did the following (note, admin access is required):
Open Terminal and navigate to folder /private/var/tmp/
type 'whoami' to see your exact user name.
Let's say your user name is 'dogtest'. type 'sudo chown dogtest:admin printd'. You'll get a warning that basically asks you to make sure you know what you're doing.
Enter your admin password and hit enter.
Now you have ownership of the printd file and can do what you want with it. Rename the file to something else by typing 'mv printd printd-ren'.
Open iOS Simlulator and Printer Simulator.
Open Safari in iOS Simulator and go to any webpage.
Tap the Share button at the bottom center and choose Print.
Follow the prompts to complete the print. You should see a lot more activity in the Printer Simulator log window. At this point the printd file is recreated with your account permissions (that's good).
Quit both iOS Simlulator and Printer Simulator.
Re-rerun your iOS app in the simulator and then reopen Printer Simulator.
Now you should be able to simulate Air Print from your app and the print-out will open in Preview as a PDF.
I hope this solves the problem for you or at least points you in the right direction. Good luck.
Try removing
/private/var/tmp/printd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With