Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AirPrint Connection Refused Error

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+.

like image 960
Sam Spencer Avatar asked Apr 15 '12 14:04

Sam Spencer


People also ask

Why is my printer not connecting to AirPrint?

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.

Why can't I print from my iPhone to my AirPrint?

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.

How do I enable AirPrint on my Canon printer?

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].


2 Answers

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):

  1. Open Terminal and navigate to folder /private/var/tmp/

  2. type 'whoami' to see your exact user name.

  3. 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.

  4. Enter your admin password and hit enter.

  5. 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'.

  6. Open iOS Simlulator and Printer Simulator.

  7. Open Safari in iOS Simulator and go to any webpage.

  8. Tap the Share button at the bottom center and choose Print.

  9. 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).

  10. Quit both iOS Simlulator and Printer Simulator.

  11. Re-rerun your iOS app in the simulator and then reopen Printer Simulator.

  12. 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.

like image 83
Jeff Avatar answered Oct 18 '22 04:10

Jeff


Try removing

/private/var/tmp/printd

like image 3
mincemeat Avatar answered Oct 18 '22 03:10

mincemeat