Từ ứng dụng của tôi, làm cách nào để cho phép người dùng in tài liệu hoặc trang từ iPhone hoặc iPad? Phiên bản hỗ trợ iOS nào in?Có thể in từ ứng dụng iPhone và iPad không?
7
A
Trả lời
6
Bạn có thể in trên bất kỳ trình phát đa nhiệm nào có khả năng chạy iOS 4.2 trở lên. Xem phần này để biết thêm thông tin: http://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Printing/Printing.html#//apple_ref/doc/uid/TP40010156-CH12-SW1
17
Đây là một mã đơn giản.
-(void)printItem {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *imageFromCurrentView = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
printController.printingItem = imageFromCurrentView;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGrayscale;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
[printController presentAnimated:YES completionHandler:completionHandler];
}