Я использую, как показано ниже, один раз придет вариант выбора принтера, и после него каждый раз будет происходить тихая печать
- (void)printCard:(UIImage*)printImage{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSURL *printURL = [NSURL URLWithString:[defaults stringForKey:@"printURLLink"]];
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
{
if(printURL)
{
UIPrinter *printer = [UIPrinter printerWithURL:printURL];
[UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printer];
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
controller.printingItem = printImage;
if(printer)
{
[controller printToPrinter:printer 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);
}
}];
}
}
else
{
UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
[printPicker presentFromRect:printCardBtn.frame inView:self.view animated:YES completionHandler:
^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
{
if (userDidSelect)
{
[UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
NSURL *printerURL = printerPicker.selectedPrinter.URL;
NSLog(@"printerURL--->%@",printerURL.absoluteString);
[defaults setObject:[printerURL absoluteString] forKey:@"printURLLink"];
[defaults synchronize];
UIPrinter *printer = [UIPrinter printerWithURL:printerURL];
[UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printer];
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
controller.printingItem = printImage;
if(printer)
{
[controller printToPrinter:printer 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);
}
}];
}
}
}];
}
}
}