如何使用AirPrint打印NSString?
我真的遇到了这个问题。我不知道出了什么问题,但它吐了出来:
错误:尝试显示没有打印源(项目/项目/格式化程序/渲染器)的打印选项
如果我将其设置为打印png图像,而不是NSString的内容,则代码可以正常工作。
这是我的代码:
- (IBAction)pushPrint:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
[dateFormatter setDateFormat:@"dd/MM/YY HH:mm:ss"];
NSString* currentTime = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *path = [[NSBundle mainBundle] pathForResource:t[NSString stringWithFormat:@"Results Printoutn"
"n"
"%@n"
"n"
"n"
"%@", currentTime, pasteboard.string] ofType:nil];
NSData *myData = [NSData dataWithContentsOfFile:path];
UIPrintInteractionController *print = [UIPrintInteractionController sharedPrintController];
print.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
print.printInfo = printInfo;
print.showsPageRange = YES;
print.printingItem = myData;
void (^completionHandler)(UIPrintInteractionController *,BOOL, NSError *) = ^(UIPrintInteractionController *print,BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"houston we have a problem");
}
};
[print presentAnimated:YES completionHandler:completionHandler];
}
没有找到相关结果
已邀请:
1 个回复
响摔衅幸
,但您正在尝试加载文件路径无法生效的文件。因此,
很可能是
(请与调试器确认)因此错误信息是正确的(
不得为
)。 要打印简单文本,请创建
(带
)的实例,并将该实例分配给
。