@interface HistoryDetailViewController : UIViewController {
}
@property (retain, nonatomic) IBOutlet UIBarButtonItem *printBarButton;
@property (nonatomic, retain) IBOutlet UILabel *name, *street, *city, *phone, *confNumber, *occupants, *cost, *arrive,
- (IBAction)printBooking:(id)sender;
-(void)airPrintEvent
{
// [mainDrawView airPrintEvent];
if ([UIPrintInteractionController isPrintingAvailable])
{
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
NSString *pngPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"/Annotation/%d.png",[[DrawInfo sharedInstance] getDrawIndex]]];
NSData *myData = [NSData dataWithContentsOfFile:pngPath];
if(pic && [UIPrintInteractionController canPrintData: myData] ) {
NSLog(@"%s",__func__);
// pic.delegate =(id<UIPrintInteractionControllerDelegate>) self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
printInfo.jobName = [NSString stringWithFormat:@"Reservation-%d",[[DrawInfo sharedInstance] getDrawIndex]];
printInfo.duplex = UIPrintInfoDuplexNone;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = myData;
pic.delegate = self;
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);
}
};
[pic presentFromRect:CGRectMake(850,150,1,1) inView:self.view animated:YES completionHandler:completionHandler];
}
}
}
參考:
http://vivianaranha.com/airprinting-tutorial-in-3-steps/