Function that sends an image to AirPrint

I am trying to find a feature that allows me to print using AirPrint.

I have a btnPrint button that when pressed should print myPic.jpg on the default AirPrint device. But I can not understand if there is such a function.

I can not find much documentation on AirPrint in xcode.

+4
source share
1 answer

Apple has print documentation that is likely to benefit you.

The following is the Objective-C code for AirPrint :

Check print availability:

 if ([UIPrintInteractionController isPrintingAvailable]) { // Available } else { // Not Available } 

Printing after pressing a button:

 -(IBAction) buttonClicked: (id) sender; { NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@, %@",self.encoded.text, self.decoded.text]; [printBody appendFormat:@"\n\n\n\nPrinted From *myapp*"]; UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; pic.delegate = self; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = self.titleLabel.text; pic.printInfo = printInfo; UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody]; textFormatter.startPage = 0; textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins textFormatter.maximumContentWidth = 6 * 72.0; pic.printFormatter = textFormatter; [textFormatter release]; 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 presentFromBarButtonItem:self.rightButton animated:YES completionHandler:completionHandler]; } 
+4
source

Source: https://habr.com/ru/post/1432948/


All Articles