How can make a IBAction method for printing a UITextView with AirPrint in objective-c?
The following method uses the name of the file to be printed and also the bar button code from where you want the airprint popup to be shown. It works for me and im sure will be helpfull
-(void)printJob:(int)jobType:(NSString*)jobName:(UIBarButtonItem *)barButton{
NSString *path;
if ([jobName isEqualToString:@"Printout.png"]) {
path= [self documentsPathForFileName:@"Printout.png"];
}
NSData *mydata=[NSData dataWithContentsOfFile:path];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = mydata;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not complete because of error: %@", error);
}
};
[pic presentFromBarButtonItem:barButton animated:YES completionHandler:completionHandler];
}