В моем приложении iOS у меня есть следующий код, который используется для AirPrinting простой 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];
}
}
Когда я запускаю свой проект (для его тестирования), это ошибка, которую я получаю в окне отладчика вывода, когда я нажимаю «Печать» в UIPrintInteractionController:
Simulated\032InkJet\032@\032USER\032NAME\032iMac._ipp._tcp.local.: startJob: Unable to connect to printd: Connection refused
Я получаю эту ошибку в симуляторе iOS 5.1. с помощью симулятора печати. Почему я получаю эту ошибку? Мне кажется, это связано с тем, как я использую Симулятор печати.
Приветствуется любая помощь, и, как примечание, кто-нибудь знает, как отобразить контроллер UIPrintInteraction из обычного UIButton на iPad вместо BarButtonItem?
РЕДАКТИРОВАТЬ:Следует отметить, что AirPrint настраивается автоматически при использовании общих таблиц в iOS 6.0+.