Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to print a NSString using AirPrint?
    text
    copied!<p>Im having real trouble with this one. I dont know what is wrong, but it spits this out:</p> <p>ERROR: attempting to display print options with no printing source(item/items/formatter/renderer) set</p> <p>The code works if i set it to print a png image, but not the contents of a NSString.</p> <p>Here is my code:</p> <pre><code>- (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 Printout\n" "\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 &amp;&amp; error) { NSLog(@"houston we have a problem"); } }; [print presentAnimated:YES completionHandler:completionHandler]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload