Trong ứng dụng iOS của tôi, tôi có mã sau đang được sử dụng để AirPrinting một NSString đơn giản.Kết nối AirPrint bị từ chối Lỗi
#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];
}
}
Khi tôi chạy dự án của tôi (để kiểm tra nó), đây là lỗi tôi nhận được trong Output Debugger Window khi tôi chạm vào "In" trên UIPrintInteractionController:
Simulated\032InkJet\[email protected]\032USER\032NAME\032iMac._ipp._tcp.local.: startJob: Unable to connect to printd: Connection refused
tôi nhận được lỗi này trong Trình mô phỏng iOS 5.1 bằng Trình mô phỏng in. Tại sao tôi nhận được lỗi này? Tôi có cảm giác nó liên quan đến cách tôi đang sử dụng Trình mô phỏng in.
Bất kỳ trợ giúp nào được đánh giá cao, và cũng giống như một lưu ý phụ, có ai biết cách hiển thị bộ điều khiển UIPrintInteraction từ một UIButton bình thường trên iPad thay vì một BarButtonItem không?
EDIT: Cần lưu ý rằng AirPrint được tự động thiết lập khi sử dụng Share Sheets trong iOS 6.0+.
Hoạt động. Vui lòng sử dụng lệnh 'CD/private/var/tmp /' – Hassy