IOS Printing Without UIPrintInteractionController Permission

I am studying a potential application for a client, and I had a question that I could not find the answer to. What I would like to do is print automatically, without displaying the UIPrintInteractionController . The important point I have to do is not be a production application. I know that otherwise it could violate the user's privacy, just to print without the consent of the user, but again this will not be a public application in the App Store. One application that I found seems to have Printer Pro feature. The user will be prompted to print a test page, and the page will be printed without the appearance of the UIPrintInteractionController - this application is in the store, so I assume that this is a legitimate way to do this. Does anyone know how to do this?

+6
source share
2 answers

As far as I know, it is impossible to print in iOS7 without calling the UIPrintInteractionController and displaying the system print dialog box. A.

However, iOS8 now provides a position to print directly to print without displaying a dialog. The main idea is that you get a UIPrinter object and use it in combination with the new - printToPrinter:completionHandler: method of the UIPrintInteractionController for printing without displaying a dialog box.

Getting the UIPrinter object for your printer can be done in several ways.

The easiest is to use the new UIPrinterPickerController . But this will show a dialogue and therefore does not meet your needs.

An alternative is to create a printer through its URL using the UIPrinter + printerWithURL: method. I don’t quite understand how to get this URL, but it can be contained in the administration pages of HTML printers. And I believe that you can get it programmatically using the Bonjour API. More details here:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/NetServices/Introduction.html#//apple_ref/doc/uid/10000119i

Bonjour is a service discovery API that includes IPP printer discovery, which is the protocol used by AirPrint.

As for how Printer Pro can print without dialogue in iOS7, I would suggest that they interact with the printer at a very low level (for example, raw HTTP messages, etc.).

+5
source

Follow these steps to print documents without a hint.

First device search using the code below ...

 if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) { UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil]; [printPicker presentAnimated:YES completionHandler: ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error) { if (userDidSelect) { //User selected the item in the UIPrinterPickerController and got the printer details. [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter]; // Here you will get the printer and printer details.ie, // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title. NSURL *printerURL = printerPicker.selectedPrinter.URL; NSLog(@"printerURL--->%@",printerURL.absoluteString); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[printerURL absoluteString] forKey:@"printURL"]; [defaults synchronize]; } }]; } 

And print the documents without asking using the code below ...

 if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; UIPrinter *currentPrinterObj = [UIPrinter printerWithURL:[NSURL URLWithString:[defaults stringForKey:[defaults stringForKey:@"printURL"]]]]; UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; if(currentPrinterObj) { [controller printToPrinter:currentPrinterObj completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { if(completed) { } else { NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code); } }]; } } 
0
source

All Articles