CortexA8 CortexA8 - 4 months ago 48
iOS Question

Get the Job Status of UIPrintInteractionController in Swift

I have a problem: I want to know the status of the print job. I'm printing out a PDF file which is temporarily stored in a cloud drive. I want to delete that file after the print job is done. How can I realize this in swift?
Here is a snippet of my code:

// 1
let printController = UIPrintInteractionController.sharedPrintController()
// 2
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfoOutputType.General
printController.showsNumberOfCopies = false
printController.showsPageRange = false
printInfo.jobName = "PDF ID: " + pdfObjectID
printController.printInfo = printInfo

// 3
//let formatter = UIMarkupTextPrintFormatter(markupText: "Test")
let formatter = pdf.viewPrintFormatter()
formatter.contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
printController.printFormatter = formatter

// show PrintController
printController.presentAnimated(true, completionHandler: nil)

Do you have any suggestions?
Thanks :)


I haven't tested it myself, but according to the documentation, you can pass a UIPrintInteractionCompletionHandler as completionHandler: parameter:

When a print job concludes, you can reset any state set up for printing and do related housekeeping tasks.

A simple example:

    printController.presentAnimated(true) { (controller, success, error) -> Void in
        if success {
            // Printed successfully
            // Remove file here ...
        } else {
            // Printing failed, report error ...