1
我需要在後臺無需用戶交互的Xcode中的AirPrint。我不在乎是否必須使用第三方框架來執行此操作。這是我有的代碼,但需要用戶的交互。自動AirPrint IOS
NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@",TextField.text];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"PrintJob";
pic.printInfo = printInfo;
UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody];
textFormatter.startPage = 0;
textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0);
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);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
如果有人能幫上忙,那就太好了!
想要自動打印而不進行任何操作? – iOS
你看了嗎?:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPrintInteractionController_Class/index.html#//apple_ref/occ/instm/UIPrintInteractionController/printToPrinter:completionHandler: – tptcat
是@ DarjiJigar這就是我想要做的 – Connor