Pushing a UIPrintInteractionController to a UINavigationController stack

2.8k Views Asked by At

The documentation for UIPrintInteractionControllerDelegate seems to suggest that you can use printInteractionControllerParentViewController: to return a UIViewController that can be used to push the UIPrintInteractionController into a standard UINavigationController stack, in much the same way that it is done in Pages.app for iOS, but despite my attempts to do so, all I've managed to do is push an empty UIViewController object to the stack, and not much else.

Is there anyone who has any ideas on how this is done, or whether it can be done at all?

(Just to be clear, I am not interested in any methods that use private APIs or the like.)

1

There are 1 best solutions below

2
On BEST ANSWER

I had the same issue with trying to get the Printer options to appear in a NavigationController similar to Pages.
The important bit is implementing the printInteractionControllerParentViewController of the UIPrintInteractionControllerDelegate to return the NavigationController.
The method will only be invoked from a present method of the UIPrintInteractionController.
Apple docs on UIPrintInteractionControllerDelegate

Some example code:

// Just some code to return a UIPrintInteractionController
// Important to set delegate to self
- (UIPrintInteractionController *)printContent {
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
if  (pic && [UIPrintInteractionController canPrintURL:[self fileToPrint]]) {
    pic.delegate = self;
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"OutputFile";
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    pic.printInfo = printInfo;
    pic.showsPageRange = YES;
    pic.printingItem = self.fileToPrint;
}
return pic;
}

Implement the printInteractionControllerParentViewController method of the delegate.

// Implement the delegate method simply to return navigationController
- (UIViewController *)printInteractionControllerParentViewController:(UIPrintInteractionController *)printInteractionController{
return self.navigationController;
}

The delegate will only be called if you run a Present method of the UIPrintInterfaceController e.g. presentFromRect:

// Need to call a present method to invoke the delegate method
[[self printContent] presentFromRect:[self.view frame] inView:self.view animated:NO completionHandler:completionHandler];